- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hey guys,
Working with longitudinal data with lots of admission/discharge times. The data is entered into the .csv file as date + military time in the same cell, for example: 01/03/2011 0534.
Trying ti get SAS to read the whole entry but it only reads the date part, ignores the time. It autimatically assigns the format 'MMDDYY10' to these date-time columns. Tried to use various date-time informats to no avail, keep getting an error. Also tried to use the 'Picture statement' in PROC FORMAT to customize my own date-time variable. SAS wont budge.
Here's a copy of my code:
FILENAME REFFILE '/folders/myshortcuts/SAS/PIMs.csv';
/*Define your own date-time format using a date-time "Picture" options*/
proc format;
picture Nada other= '%0m/%0d/%Y %0H%0M' (datatype=datetime);
run;
data WORK.PIMs ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile REFFILE delimiter = ',' MISSOVER DSD firstobs=2 ;
informat Arrv_Date_Time datetime_20. ;
informat Disch_Date_Time MDYAMPM25. ;
format Arrv_Date_Time Nada. ;
format Disch_Date_Time Nada. ;
input
Arrv_Date_Time
Disch_Date_Time
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
___________________________________________________________________________________________________________
Any input is much appreciated, thanks!
Nada
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SAS easily reads 24h-clock times, but has no provisions for reading times with no separator, so you need to transform the value.
Here are two examples of options you have, one uses a custom informat to do the transformation.
proc format;
invalue val2dtm 's/(.{10}) (\d\d)(\d\d)/\1:\2:\3/' (regexpe)=[anydtdtm.];
run;
data HAVE;
A='01/03/2011 0534';
B=input(A,val2dtm.);
putlog B= datetime20.;
run;
data HAVE;
A='01/03/2011 0534';
B=prxchange('s/(\d\d).(\d\d).(\d{4}).(\d\d)(\d\d)/\3-\1-\2T\4:\5/',1,A);
C=input(B,e8601dt.);;
putlog C= datetime20.;
run;
B=01MAR2011:05:03:00
C=03JAN2011:05:34:00
(My locale uses a default data format of dd/mm/yyyy, but the code above translates your date as mm/dd/yyyy since that's what you use)