BookmarkSubscribeRSS Feed
BrinaLi
Fluorite | Level 6

Hello, 

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!

2 REPLIES 2
Reeza
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'));
run;

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

proc means data=sashelp.class;
class sex;
run;

 

UCLA introductory tutorial on macro variables and macros

https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/

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 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

Examples of common macro usage

https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

 

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