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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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