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-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

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
  • 1130 views
  • 1 like
  • 2 in conversation