BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to define macro with 12 arguments (12 months in structure YYMM).

 

Let's say that the macro is defined by:

%Macro RRR(YYMM1,YYMM2,YYMM3,YYMM4,YYMM5,YYMM6,YYMM7,YYMM8,YYMM9,YYMM10,YYMM11,YYMM12);

 

And I want to run the macro with following arguments:

 

 

%RRR(2502,2501,2412,2411,2410,2409,2408,2407,2406,2405,2404,2403)
%RRR(2501,2412,2411,2410,2409,2408,2407,2406,2405,2404,2403,2402)

%RRR(2412,2411,2410,2409,2408,2407,2406,2405,2404,2403,2402,2401)
%RRR(2411,2410,2409,2408,2407,2406,2405,2404,2403,2402,2401,2312)
%RRR(2410,2409,2408,2407,2406,2405,2404,2403,2402,2401,2312,2311)
%RRR(2409,2408,2407,2406,2405,2404,2403,2402,2401,2312,2311,2310)
%RRR(2408,2407,2406,2405,2404,2403,2402,2401,2312,2311,2310,2309)
%RRR(2407,2406,2405,2404,2403,2402,2401,2312,2311,2310,2309,2308)
%RRR(2406,2405,2404,2403,2402,2401,2312,2311,2310,2309,2308,2307)
%RRR(2405,2404,2403,2402,2401,2312,2311,2310,2309,2308,2307,2306)
%RRR(2404,2403,2402,2401,2312,2311,2310,2309,2308,2307,2306,2305)
%RRR(2403,2402,2401,2312,2311,2310,2309,2308,2307,2306,2305,2304)
%RRR(2402,2401,2312,2311,2310,2309,2308,2307,2306,2305,2304,2303)
%RRR(2401,2312,2311,2310,2309,2308,2307,2306,2305,2304,2303,2302)

%RRR(2312,2311,2310,2309,2308,2307,2306,2305,2304,2303,2302,2301)
%RRR(2311,2310,2309,2308,2307,2306,2305,2304,2303,2302,2301,2212)
%RRR(2310,2309,2308,2307,2306,2305,2304,2303,2302,2301,2212,2211)
%RRR(2309,2308,2307,2306,2305,2304,2303,2302,2301,2212,2211,2210)
%RRR(2308,2307,2306,2305,2304,2303,2302,2301,2212,2211,2210,2209)
%RRR(2307,2306,2305,2304,2303,2302,2301,2212,2211,2210,2209,2208)
%RRR(2306,2305,2304,2303,2302,2301,2212,2211,2210,2209,2208,2207)
%RRR(2305,2304,2303,2302,2301,2212,2211,2210,2209,2208,2207,2206)
%RRR(2304,2303,2302,2301,2212,2211,2210,2209,2208,2207,2206,2205)
%RRR(2303,2302,2301,2212,2211,2210,2209,2208,2207,2206,2205,2204)
%RRR(2302,2301,2212,2211,2210,2209,2208,2207,2206,2205,2204,2203)
%RRR(2301,2212,2211,2210,2209,2208,2207,2206,2205,2204,2203,2202)


%RRR(2212,2211,2210,2209,2208,2207,2206,2205,2204,2203,2202,2201)
%RRR(2211,2210,2209,2208,2207,2206,2205,2204,2203,2202,2201,2112)

 

My question---

What is the way to run macro and write it via code and not manfully type it?

I mean,  what is the way to create these statements  of %RRR(.........)   via code and not type it manually??

 

 

 

2 REPLIES 2
Kurt_Bremser
Super User

You have two nested loops, the outer going backwards from February 2025 to November 2022, and the inner that counts back 11 months from the starting month. Define those two loops (using SAS functions like INTNX), and then run the code for the resulting month.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 832 views
  • 5 likes
  • 3 in conversation