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
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.
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.
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;
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.
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.
Ready to level-up your skills? Choose your own adventure.