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

Suppose there  is a table and in table ,a column named state has 28 different values.I want to call 5 states names, for this i want to write a single macro which will call those 5 states.

 

Kindly help.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

It is not clear what you are asking for.  A simple example of what you have and what you want to get would help.

 

If you are looking to subset your data then a WHERE statement (not a macro or a macro variable) is what you want.

 

You could use a macro variable to help you generate the WHERE statement.

%let state_list = 'NY' 'CT' 'DE' ;
data want;
  set have;
  where state in (&state_list);
run;

An actual macro is not needed unless you need to do something more complex.

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You can use the "in" operator in where conditions, no macro needed.

 

To illustrate your issue, post example data in a data step with datalines (use the "little running man" icon for posting code), and what you expect to get out of it.

Tom
Super User Tom
Super User

It is not clear what you are asking for.  A simple example of what you have and what you want to get would help.

 

If you are looking to subset your data then a WHERE statement (not a macro or a macro variable) is what you want.

 

You could use a macro variable to help you generate the WHERE statement.

%let state_list = 'NY' 'CT' 'DE' ;
data want;
  set have;
  where state in (&state_list);
run;

An actual macro is not needed unless you need to do something more complex.

 

asuman
Obsidian | Level 7
Thanks Tom,This is what i was looking for.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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