BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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?

7 REPLIES 7
yabwon
Amethyst | Level 16

Did you at least tried to "google" it?

 

yabwon_0-1712661593185.png

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ronein
Onyx | Level 15

May you please show code?

PaigeMiller
Diamond | Level 26

Please give it a try. From your other questions, I know you have written macros before.

--
Paige Miller
yabwon
Amethyst | Level 16
%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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

Why don't you just use format YYMMN4. instead of 

 

cats(mod(year(sd),100),put(month(sd),z2.));
--
Paige Miller
yabwon
Amethyst | Level 16

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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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
  • 7 replies
  • 1561 views
  • 1 like
  • 3 in conversation