Hello,
I am using the script below to put all the values into macro variables but it reads only the first value. Why?
How to solve that Issue.
Vartable 3 first observations only
name1 name2
ps.startDate, pt.startDate = ps.startDate,
ps.endDate, pt.endDate = ps.endDate,
ps.status, pt.status = ps.status,
proc sql noprint ;
select strip(name1), strip(name2)
into :varlist1, :varlist2
from vartable;
Quit;
%put &=varlist1.;
%put &=varlist2.;
When you fail to add "separated by", SAS thinks you only want one value.
Because that is what you asked it to do.
You can either concatenate the values into single macro variables by using the SEPARATED BY keyword. (PS Removing the leading spaces changes the meaning of the values. Just remove the trailing spaces.)
proc sql noprint ;
select trim(name1), trim(name2)
into :varlist1 separated by '|'
, :varlist2 separated by '|'
from vartable
;
%let nobs=&sqlobs;
quit;
%put &=varlist1;
%put &=varlist2;
Or you can create two SETS of variables with numeric suffixes.
proc sql noprint ;
select trim(name1), trim(name2)
into :varlist1_1 -
, :varlist2_1 -
from vartable
;
%let nobs=&sqlobs;
quit;
%put &=varlist1_1 varlist1_&nobs=&&varlist1_&nobs;
%put &=varlist2_1 varlist2_&nobs=&&varlist2_&nobs;
When you fail to add "separated by", SAS thinks you only want one value.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.