Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion of SAS Macro Variable to time stamp

I am trying to convert SAS Macro variable to timestamp and stumped while conversion. The code which I am using is given below.

%let date = '03/15/2013';
%put %sysfunc(inputn(&date,datetime26.6));

Error which I am getting is

WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range. NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.

Please let me know if someone knows answers to this.

like image 771
LonelySoul Avatar asked Mar 22 '23 13:03

LonelySoul


1 Answers

That is not a DATETIME, that is a DATE format (to INPUT, which depends on the incoming data, not the outgoing). You also need to remove the quotes, SYSFUNC treats quotes as characters, not as string delimiters.

%let date = 03/15/2013;
%put %sysfunc(inputn(&date,MMDDYY10.));

To actually create the datetime, you need to use PUT:

%let date = 03/15/2013;
%put %sysfunc(putn(%sysfunc(dhms(%sysfunc(inputn(&date,MMDDYY10.)),0,0,0)),datetime26.));

However, the better way to do this if you can is to use a date constant...

%let date=15MAR2013;
%put "&date."d;
like image 154
Joe Avatar answered Apr 10 '23 09:04

Joe