BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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.;
1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Tom
Super User Tom
Super User

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;
Astounding
PROC Star

When you fail to add "separated by", SAS thinks you only want one value.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 905 views
  • 4 likes
  • 3 in conversation