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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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