- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your -1 subtracts one second. I left that in because you never showed what you expected the result to actually be.