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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 646 views
  • 5 likes
  • 2 in conversation