BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
laura6728
Obsidian | Level 7

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 */
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

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

Reeza
Super User

Or use CALL EXECUTE to loop and call the macro 6 times, there are lots of ways to automate a macro loop.

laura6728
Obsidian | Level 7

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!

Kurt_Bremser
Super User

@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.

hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

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
  • 5 replies
  • 1740 views
  • 0 likes
  • 4 in conversation