I have several programs that I run for several different years to generation reports. Currently, I have to manually change the %let CYEAR each time I run the program, and I run it for 2010 - 2016. Is there a way for it to run 1 time for all the years I want to run?
%let CYEAR = 2010; /* YEAR OF COHORT */ %let CYEAR2 = %eval(&CYEAR. + 1); %let TERM = &CYEAR.FA; /* TERM OF COHORT */ %let NTERM = &CYEAR2.SP; /* +1 TERM TO CHECK 1 TERM RETENTION STATUS */ %let NYTERM = &CYEAR2.FA; /* +1 YEAR TO CHECK 1 YEAR RETENTION STATUS */
Don't know without seeing the rest of the code you run, but one possibility would be to wrap everything in a macro. e.g.:
%macro doit (first,last) %do cyear=&first %to &last; /* YEAR OF COHORT */ %let CYEAR2 = %eval(&CYEAR. + 1); %let TERM = &CYEAR.FA; /* TERM OF COHORT */ %let NTERM = &CYEAR2.SP; /* +1 TERM TO CHECK 1 TERM RETENTION STATUS */ %let NYTERM = &CYEAR2.FA; /* +1 YEAR TO CHECK 1 YEAR RETENTION STATUS */ %include your_actual_program.sas; %mend doit; %doit (2010,2016)
Art, CEO, AnalystFinder.com
Within a macro, you can do
%do cyear = 2010 %to 2016;
/* your code */
%end;
Don't know without seeing the rest of the code you run, but one possibility would be to wrap everything in a macro. e.g.:
%macro doit (first,last) %do cyear=&first %to &last; /* YEAR OF COHORT */ %let CYEAR2 = %eval(&CYEAR. + 1); %let TERM = &CYEAR.FA; /* TERM OF COHORT */ %let NTERM = &CYEAR2.SP; /* +1 TERM TO CHECK 1 TERM RETENTION STATUS */ %let NYTERM = &CYEAR2.FA; /* +1 YEAR TO CHECK 1 YEAR RETENTION STATUS */ %include your_actual_program.sas; %mend doit; %doit (2010,2016)
Art, CEO, AnalystFinder.com
Or use CALL EXECUTE to loop and call the macro 6 times, there are lots of ways to automate a macro loop.
I am sorry everyone, I posted this in the BASE forum and I am using EG. I am going to move this over to the EG board. Sorry, and thanks for the help!
@laura6728 wrote:
I am sorry everyone, I posted this in the BASE forum and I am using EG. I am going to move this over to the EG board. Sorry, and thanks for the help!
Not necessary. It's got more to do with Base SAS code than with EG functionality.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.