DATA Step, Macro, Functions and more

Automating Date macro variables

Reply
Contributor
Posts: 27

Automating Date macro variables

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;
SAS Super FREQ
Posts: 8,864

Re: Automating Date macro variables

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
Valued Guide
Posts: 2,177

Re: Automating Date macro variables

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 ;
SAS Super FREQ
Posts: 8,864

Re: Automating Date macro variables

Thanks, Peter! And thanks for remembering the SYMPUTX.
cynthia
Contributor
Posts: 27

Re: Automating Date macro variables

Posted in reply to Cynthia_sas
Thank you Cynthia and Peter! It worked!!
Ask a Question
Discussion stats
  • 4 replies
  • 146 views
  • 0 likes
  • 3 in conversation