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

Good morning,

 

Please help me with automating dates in my code. I currently have the following code which I have to change every month:

/*need to update at the beginning of the month*/
%let nin_TM = 01MAR2022;
%let nin_LM = 01FEB2022;
%let nin_LY = 01MAR2021;

 

Please help me with automating the dates in the above so that I don't need to manually change the dates every month. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Maxim 28: Macro Variables Need No Formats.

By using raw values, you can use your dates without having to add quotes and the trailing d everywhere you put them in code.

(Exception: when macro variables are used in human-readable output, like titles etc).

So see this code:

%let nin_TM = %sysfunc(intnx(month,%sysfunc(today()),0,b));
%let nin_LM = %sysfunc(intnx(month,&nin_tm.,-1,b));
%let nin_LY = %sysfunc(intnx(year,&nin_tm.,-1,s));

You can display the formatted values (for control) like this:

data _null_;
nin_tm = &nin_tm.;
nin_lm = &nin_lm.;
nin_ly = &nin_ly.;
format nin: date9.;
put nin_tm= nin_lm= nin_ly=;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Maxim 28: Macro Variables Need No Formats.

By using raw values, you can use your dates without having to add quotes and the trailing d everywhere you put them in code.

(Exception: when macro variables are used in human-readable output, like titles etc).

So see this code:

%let nin_TM = %sysfunc(intnx(month,%sysfunc(today()),0,b));
%let nin_LM = %sysfunc(intnx(month,&nin_tm.,-1,b));
%let nin_LY = %sysfunc(intnx(year,&nin_tm.,-1,s));

You can display the formatted values (for control) like this:

data _null_;
nin_tm = &nin_tm.;
nin_lm = &nin_lm.;
nin_ly = &nin_ly.;
format nin: date9.;
put nin_tm= nin_lm= nin_ly=;
run;
MagD
Quartz | Level 8
Thank you so much @Kurt_Bremser, your solution worked!

Thank you so much!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 657 views
  • 1 like
  • 2 in conversation