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

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