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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 904 views
  • 0 likes
  • 4 in conversation