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
SAS Super FREQ
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
SAS Super FREQ
Thanks, Peter! And thanks for remembering the SYMPUTX.
cynthia
SAS09
Calcite | Level 5
Thank you Cynthia and Peter! It worked!!

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