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

In the following code, i can get the answer for period1, but why I can't get the desired period for period2 but only got date back to 1960.  Please help, thanks.

 

%LET RUNDATE = '01OCT2016'D;

 

DATA _NULL_;
CALL SYMPUT("PERIOD1",PUT(INTNX('MONTH',&RUNDATE,-1,'E'),DATE9.));
CALL SYMPUT("PERIOD2",PUT(INTNX('MONTH',&RUNDATE,-1,'E'),DATETIME24.));
RUN;

 

%PUT &PERIOD1;
%PUT &PERIOD2;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What are you expecting for the result?

Date values are number of days from 1 Jan 1960

Datetime values are number of seconds from midnight 1 Jan 1960.

If you want a datetime value you need to do something to turn a date into datetime.

Perhaps this is close to what you want:

 

%LET RUNDATE = 01OCT2016;

DATA _NULL_;
CALL SYMPUT("PERIOD1",PUT(INTNX('MONTH',"&RUNDATE"d,-1,'E'),DATE9.));
CALL SYMPUT("PERIOD2",PUT(INTNX('dtMONTH',"&RUNDATE 00:00:00"dt,-1,'E'),DATETIME24.));
RUN;

%PUT &PERIOD1;
%PUT &PERIOD2;

View solution in original post

3 REPLIES 3
ballardw
Super User

What are you expecting for the result?

Date values are number of days from 1 Jan 1960

Datetime values are number of seconds from midnight 1 Jan 1960.

If you want a datetime value you need to do something to turn a date into datetime.

Perhaps this is close to what you want:

 

%LET RUNDATE = 01OCT2016;

DATA _NULL_;
CALL SYMPUT("PERIOD1",PUT(INTNX('MONTH',"&RUNDATE"d,-1,'E'),DATE9.));
CALL SYMPUT("PERIOD2",PUT(INTNX('dtMONTH',"&RUNDATE 00:00:00"dt,-1,'E'),DATETIME24.));
RUN;

%PUT &PERIOD1;
%PUT &PERIOD2;
scb
Obsidian | Level 7 scb
Obsidian | Level 7

It almost got what I wanted; but may i know why the datetime was 30SEP2016:23:59:59 instead of 30SEP2016:00:00:00? Any idea why?

ballardw
Super User

Your -1 subtracts one second. I left that in because you never showed what you expected the result to actually be.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 926 views
  • 0 likes
  • 2 in conversation