12-22-2016 05:17 PM
I am trying to run this and I am getting wierd date for startdt1. I am getting -01JAN1960:05:45:59. I get the same date time stamp however I try to use datetime format. I m unable to figure out why. Why is this happening and what's the fix.
12-22-2016 05:24 PM
That's because Today() returns a SAS Date (days since 1/1/1960) and not a SAS DateTime value (seconds since 1/1/1960) but format DateTime24. is for SAS DateTime values.
If you use format DateTime. for a SAS Date value then you'll end up with 1960 - and 05:45:59 is the result of the number of days treated as number of seconds.
12-22-2016 05:34 PM
Why the macro calls?
Datetimes are measured in seconds. Dates are measured in days. So when you use INTNX on a DATE and use a month interval you get DAYs as a result. The number of days is going to be MUCH smaller than the number of seconds from the base date of 1 Jan 1960. And displaying the number days with a format for seconds means you generally don't get what you want.
To turn a date into a datetime use the function DHMS
will assign a value of midnight at the start of the day.
And no real reason to go through the bit of creating a date literal.
data _null_; dateend=today(); startdt1 = dhms( intnx('month',today(),-1,'B'),0,0,0); put startdt1 datetime24.; run;
You would be much better off creating the dates in the datastep with date and time functions and then using call symputx if you need macro variables holding the values. Only bother with date or datetime literals if you as a person are going to read the resolved values. If you are going to use them in further programming such as before, after or between values in data step or where claused best to use the numeric version and simplify code avoiding all the " "d or " "dt issues.
12-23-2016 03:01 AM
Besides what the others said, your data _null_ is completely useless. The %let macro statements create no code for the data step, so it stays empty.