Search code examples
sassas-macro

SAS macro to resolve in proc sql into statement


Can anyone help me with the syntax error here. Y is dataset which contain some value let's say 1,2,3,4 (Actually it contains many records)

/*This is working fine*/
proc sql;
select count(*) into:m from y;
select x into:a1 - :a4 from y;
quit;
%put &m &a1 &a2 &a3 &a4;

/*When i am trying to create a macro which will have a1 to a4 values, it's giving me error. below is my approach*/

proc sql;
select count(*) into:m from y;
select x into:a1 - :a||trim(left(&m.)) from y;
quit;
%put &m &a1 &a2 &a3 &a4;

Please can someone help me with this, explain me the reason for error.


Solution

  • You don't need to tell how many anymore. SQL will create just enough variables.

    data y;
       do x = 1 to 4;
          output;
          end;
       run;
    proc sql;
       select count(*) into:m from y;
       select x into:a1- from y;
       quit;
    %put &m &a1 &a2 &a3 &a4;
    

    This is valid at least as of 9.3.