BookmarkSubscribeRSS Feed
Fluorite | Level 6


I am new to SAS programming and looking for some general guidance. I have a program where it creates the same table 4 times and has the same date filter on 3 columns for each table. The only difference is when it is filtered for specific payment types (i.e. the first time it is created it is only for reserves, then the 2nd time it is created its for paid in full, etc). My first thought to speed up the program is to create the table once, then filter it each time for specific information. Can this be done using a macro? For example, I would create macro A then call it 4 times with 4 different filters?


If a similar question has already been answered, please let me know!

thank you in advance!

Super User

Yes, this can be done. There are a few ways but a data set option with a WHERE statement is a good way. 


For example, if you wanted to summarize the sashelp.class data set by sex, you could do either of the following:




proc means data=sashelp.class (where=(sex='M'));

proc means data=sashelp.class;
where sex= 'F';

proc means data=sashelp.class;
class sex;


UCLA introductory tutorial on macro variables and macros

Tutorial on converting a working program to a macro

This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂

Examples of common macro usage



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
  • 2 replies
  • 1 like
  • 3 in conversation