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-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 803 views
  • 1 like
  • 3 in conversation