BookmarkSubscribeRSS Feed
SAS09
Calcite | Level 5
Does anyone have any thoughts on how I might be able to automate the below list of macro variables. Mth1 changes every month and the format of the mth varaibles need to the same yymm-1004, 1005 etc. I would greatly appreciate any ideas.

rsubmit;
%let mth1 = 1004;
%let mth2 = 1003;
%let mth3 = 1002;
%let mth4 = 1001;
%let mth5 = 0912;
%let mth6 = 0911;
%let mth7 = 0910;
%let mth8 = 0909;
%let mth9 = 0908;
%let mth10 = 0907;
%let mth11 = 0906;
%let mth12 = 0905;
endrsubmit;
4 REPLIES 4
Cynthia_sas
Diamond | Level 26
Hi:
There are a couple of different ways that you could do this. You could do this in a DATA step program and create the macro variables with CALL SYMPUT or you could do this in a Macro program and use %SYSFUNC. In either case, you'd have to use INTNX to move the dates backward in time.

My inclination would be to use CALL SYMPUT inside a DATA step program and then wrap the DATA step program in a Macro program so that the start month, year and number of months could all be provided as parameters to the macro program.

cynthia
Peter_C
Rhodochrosite | Level 12
rsubmit ;
%let mth1=1apr2010 ;
data _null_ ;
do d= 1 to 12 ;
date = intnx( 'month', "&mth1"d, 1-d) ;
mnth = put( date, yymmN4. ) ;
call symputx( 'mth' !! put( d, 2.-L), mnth ) ;
end;
stop ;
run;
endrsubmit ;
Cynthia_sas
Diamond | Level 26
Thanks, Peter! And thanks for remembering the SYMPUTX.
cynthia
SAS09
Calcite | Level 5
Thank you Cynthia and Peter! It worked!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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