BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hello everyone,

I have created a list by %let variables= var1 var2 var3 var4 var5 var6;

would like to use it as below 

data _output;

set input(keep=(&variables.));   /*var1--var6 should be taken from here*/

run;   

 

This throws an error but if I do as below, it comes correct. 

data _output;

set input;

keep &variables.;

run;

 

anyone, who has overcame this , please help me know why we can't do like the first step?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

A macro is just a code generator.

Compare next two codes - the 1st with parenthesis, the 2nd without:

/* 1 */
data output;
  set input (keep=(var1 var2 var3));
run;

/* 2 */
data output;
  set input(keep=var1 var2 var3);
run;

The first code is invalid. 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Simply loose the inner (). This works

 

data input;
   array var{10} (1 : 10);
run;

%let variables= var1 var2 var3 var4 var5 var6;

data output;
   set input(keep=&variables.); 
run;
ChrisNZ
Tourmaline | Level 20

Always test your macro-free code before adding the macro layer. Always.

Here the code is invalid.

Shmuel
Garnet | Level 18

A macro is just a code generator.

Compare next two codes - the 1st with parenthesis, the 2nd without:

/* 1 */
data output;
  set input (keep=(var1 var2 var3));
run;

/* 2 */
data output;
  set input(keep=var1 var2 var3);
run;

The first code is invalid. 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 680 views
  • 0 likes
  • 4 in conversation