BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ramgouveia
Obsidian | Level 7

I have the following code:

/*Importação para a memória da base de Janeiro*/;
Data D201901 (keep=U);
	Set D201901;
Run;

Data E201901s (keep=U);
	Set E201901s;
Run;

Instead of 201901 I want n-24, i.e., the 24th previous month.

 

I want to create a monthly routine program.

 

Can you help me writing the proper code?

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Would you like to hardcode the "specific month" like this?

%let basemon=202101;
%let mon=%sysfunc(intnx(month,%sysfunc(inputn(&basemon,yymmn6.)),-24),yymmn.);

This yields 201901.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @ramgouveia,

 


@ramgouveia wrote:

Instead of 201901 I want n-24, i.e., the 24th previous month.


Do you mean "today minus 24 months"? If so, you can (at the beginning of your program) define a macro variable, say MON, in a way that dynamically creates the YYYYMM expression by subtracting 24 months from the date when the program runs:

%let mon=%sysfunc(intnx(month,%sysfunc(today()),-24),yymmn.);

Submitted today, this yields 201904.

 

Then replace all occurrences of 201901 in your code by

&mon.

For example, write

EFAT_&mon.s

instead of EFAT_201901s.

 

 

 

 

ramgouveia
Obsidian | Level 7

Thank you @FreelanceReinh 

 

But here:

 

%let mon=%sysfunc(intnx(month,%sysfunc(today()),-24),yymmn.);

Instead of today function how can I define a specific month?

FreelanceReinh
Jade | Level 19

Would you like to hardcode the "specific month" like this?

%let basemon=202101;
%let mon=%sysfunc(intnx(month,%sysfunc(inputn(&basemon,yymmn6.)),-24),yymmn.);

This yields 201901.

ramgouveia
Obsidian | Level 7

Thank you @FreelanceReinh 

 

Both solutions are useful.

 

The second is best for us now.

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
  • 4 replies
  • 1518 views
  • 5 likes
  • 2 in conversation