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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.