BookmarkSubscribeRSS Feed
LockieFerguson
Calcite | Level 5

I have 3 proc report statements that I need to run 25 times to get my desired result (one time for each "grantee"). I know there is a simple way to do this with a macro(?), but my experience with macros is limited and I'm struggling. 

 

I want to run the following reports 25 times (1 for each value of the variable "grantee") - i.e., run the reports through once on a subset of data where grantee =grantee1, then run it through again where grantee=grantee2, etc. I have it set up in the code below with a %let statement - this works when i type the grantee name in, one by one, and run it 25 times.  I'm sure there's a faster way where it automatically runs through each value of grantee without having to change the %let statement. Any advice? (I feel like i'm missing something obvious and simple - thank you in advance!)

2 REPLIES 2
Kurt_Bremser
Super User

What keeps you from using grantee as a group column and insert page breaks for group changes?

 

PS please post your code for one grantee, and give us a simple example of your data for testing. Post it as a data step with datalines.

Reeza
Super User

See Step 5/6 in the second link.

 

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


SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 398 views
  • 0 likes
  • 3 in conversation