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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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