BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
data test;
my_date = INTNX('MONTH',&tday,-1,'B') ;
format my_date nldatm.;
run;

The above code returns 01Jan1960:06:19:57 and not the current beginning of last month.  In this case I want 01Jun2022:00:00: etc..........  I need this to use it in a dataset because the field in the dataset uses datetime

3 REPLIES 3
ballardw
Super User

If you want to increment datetime values the interval is DTmonth or DTyear or DTday. See the pattern?

 

Since dates are counts of days and datetimes are seconds the intervals must be different.

Tom
Super User Tom
Super User

What does the macro variable TDAY have in it?

Your code is treating it as a DATE in the assignment statement, since the MONTH interval is for DATE values.

But then you are attaching a DATETIME format.

 

If the value of &TDAY is a datetime value (number of seconds since 1960) then you want to use the DTMONTH interval in the INTNX() function call.

Sajid01
Meteorite | Level 14

If you want the date for pervious month, beinning of the day, then as pointed out by @ballardw , DTMonth should be used instead of Month in the INTNX function. If the todays date is being used, then the code will like this

data test;
format my_date nldatm.; my_date = INTNX('DTMONTH',datetime(),-1,'B') ; run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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