02-20-2014 11:45 AM
You would have to modify this somewhat, but here is a macro I wrote for a similar problem. In my case, the input dates were character vars and all
"DD/MM/YYYY hh:mm" For me, it was important to be able to set impossible dates to missing. I also use the year variable to create a calendar year class var, which can be helpful.
%MACRO MKSASDT(DATEVAR, NEWDTVAR, FIRSTYR, LASTYR, I);
_&I._TEMPDT = COMPRESS(&DATEVAR);
_&I._TEMPDT = STRIP(_&I._TEMPDT);
_&I._MM = SUBSTR(_&I._TEMPDT, 1,2);
_&I._DD = SUBSTR(_&I._TEMPDT, 4,2);
_&I._YY = SUBSTR(_&I._TEMPDT, 7,4);
_&I._HH = SUBSTR(_&I._TEMPDT, 11,2);
_&I._TT = SUBSTR(_&I._TEMPDT, 14,2);
IF _&I._YY<&FIRSTYR OR _&I._YY>&LASTYR THEN _&I._YY=.;*GET RID OF WAY PAST AND FUTURE DATES;
&NEWDTVAR._DT = MDY(_&I._MM, _&I._DD, _&I._YY);
&NEWDTVAR._DTM = DHMS(&NEWDTVAR._DT, _&I._HH, _&I._TT, 0);
FORMAT &NEWDTVAR._DT DATE9. &NEWDTVAR._DTM DATETIME20.;
02-20-2014 12:06 PM
the informat anytdtm will read you data.
Try something like:
input datetme anydtdtm20.;
put datetme datetime20.;
The log shows the new formatted value:
Need further help from the community? Please ask a new question.