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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1218 views
  • 0 likes
  • 4 in conversation