Hello
I want to run macro that contain 6 arguments.
I want to run it X60 times (Each time with different macro arguments)
Each argument contain value in format YYMM
Here is the require macro run: (60 runs)
%RRR(M6=2211,M5=2210,M4=2209,M3=2208,M2=2207,M1=2206)
%RRR(M6=2210,M5=2209,M4=2208,M3=2207,M2=2206,M1=2205)
%RRR(M6=2208,M5=2208,M4=2207,M3=2206,M2=2205,M1=2204)
and so on
%RRR(M6=1801,M5=1712,M4=1711,M3=1710,M2=1709,M1=1708)
What is the best way to create the code that it 60 times as I mentioned?
Did you at least tried to "google" it?
You create 6 macro variables that are one month apart, lets call them &DATE1 through &DATE6 where initially &date1 is the date corresponding to 2206, and then &DATE2 is one month after &DATE1, and so on.
Then you create a loop with index &I that goes 1 to 59, and each time &DATE1 is decreased by &I months, and then &DATE2 through &DATE6 are recalculated accordingly.
Please give it a try.
Do not try to do this with dates as integers like 2206. YOu want to do this with actual SAS date values, which are the number of days since 01JAN1960, formatted as YYMMN4.
May you please show code?
Please give it a try. From your other questions, I know you have written macros before.
%macro RRR(M6=I,M5=am,M4=lazy,M3=and,M2=not,M1=googling);
%put &M6. &M5. &M4. &M3. &M2. &M1.;
%mend RRR;
%RRR();
data _Null_;
startdate="01nov2022"d;
do i = 0 to 59; /* 60 times including current month */
array M[0:5] $4 M6-M1;
length str $ 512;
str=" ";
do j=0 to 5;
sd=intnx("month",startdate,-i-j,"S");
M[j] = cats(mod(year(sd),100),put(month(sd),z2.));
str=catx(",",str,catx("=",vname(M[j]),M[j]));
end;
call execute('%nrstr(%RRR(' !! strip(str) !! '))');
end;
run;
Why don't you just use format YYMMN4. instead of
cats(mod(year(sd),100),put(month(sd),z2.));
Good point, updated:
%macro RRR(M6=I,M5=am,M4=lazy,M3=and,M2=not,M1=googling);
%put &M6. &M5. &M4. &M3. &M2. &M1.;
%mend RRR;
%RRR();
data _Null_;
startdate="01nov2022"d;
do i = 0 to 59;
array M[0:5] $4 M6-M1;
length str $ 512;
str=" ";
do j=0 to 5;
sd=intnx("month",startdate,-i-j,"S");
str=catx(",",str,catx("=",vname(M[j]),put(sd,YYMMN4.)));
end;
call execute('%nrstr(%RRR(' !! strip(str) !! '))');
end;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.