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

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

1 ACCEPTED SOLUTION

Accepted Solutions
esjackso
Quartz | Level 8

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

View solution in original post

4 REPLIES 4
esjackso
Quartz | Level 8

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

GuiVtzl
Fluorite | Level 6

Thanks a lot, the macro delimiter works fine and the result's exactly what I expected.

Sincerely

GV

Astounding
PROC Star

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.

GuiVtzl
Fluorite | Level 6

Thanks Astounding ! It will make it better !

Sincerely

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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