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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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