Hello !
Here's my problem : I've got a table with variables like TEST_Q3_07 TEST_Q4_07 [...] TEST_Q4_2012 THING_Q3_07 THING_Q4_07 [...] THING_Q4_2012
What I'd like is through a prompt and a KEEP statement allow the user to choose which set he'd like to keep.
My prompt would create a macro variable call &Variable and possible values would be TEST or THING and then my question is : how do I include a set of variables in a KEEP statement where's a prompt involved ?
Here's one of the codes I tried, unsuccessfully ;
DATA HISTO ; SET HISTO ;
KEEP=&Variable_Q3_07 &Variable_Q4_07 [...] &Variable_Q4_12;
run;
Thank you
did you try the code with the macro delimiter in the keep statement macro variables?
KEEP &Variable._Q3_07 &Variable._Q4_07 [...] &Variable._Q4_12;
by the way if you are using keep as part of the data step there is no = in the syntax. If you move to the set statement and use as a data set option Histo (keep= blah ); they you use the = and this might be a better option depending on the size of the data you are using.
See if that helps
EJ
did you try the code with the macro delimiter in the keep statement macro variables?
KEEP &Variable._Q3_07 &Variable._Q4_07 [...] &Variable._Q4_12;
by the way if you are using keep as part of the data step there is no = in the syntax. If you move to the set statement and use as a data set option Histo (keep= blah ); they you use the = and this might be a better option depending on the size of the data you are using.
See if that helps
EJ
Thanks a lot, the macro delimiter works fine and the result's exactly what I expected.
Sincerely
GV
I agree with all the recommendations so far, especially moving KEEP to the SET statement:
data histo;
set histo (keep=some list of variables);
run;
Also note ... if you want ALL variable names that begin with TEST or THING, you can abbreviate the code:
data histo;
set histo (keep=&variable:);
run;
The colon modifier (no space allowed before the colon) will automatically indicate that your list of variables includes all variable names that start with &VARIABLE
Good luck.
Thanks Astounding ! It will make it better !
Sincerely
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.