Hi,
I am using SAS9.4 an trying to import a csv file with the import wizard.
I am having difficulty with a date and time format. My data comes in with a date and time in the one cell in the format 'DD-MM-YYYY HH:MM:SS'. I would like to continue working with it in this format, but am not sure whether SAS recognises it as date and time.
Here is the import wizard code (incomplete) I am currently using, but it imports the SET_DATE variable as a text:
%macro import(wk);
data WORK._&wk.;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "C:\Users\Pete\Desktop\&wk..csv" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat SORT_ID $10. ;
informat EVENT_ID $10. ;
informat SET_DATE $21. ;
format SORT_ID $10. ;
format EVENT_ID $10. ;
format SET_DATE best. ;
input
SPORTS_ID $
EVENT_ID $
SETTLED_DATE $
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
I have tried using ANYDTDTME21 and several other formats but am having trouble reading in that variable in a usable datetime format. Any help wold be great, thanks!
Try an informat of anydtdm21 and a format of datetime21
Hi Reeza,
Thanks for the reply - that worked a charm.
I suspected it may have had something to do with inconsistency between the in/format aspect, but am evidently quite new to this.
Thanks for your help.
Ed
Every so often, depending on the actual format of the text the ANYDTDTME works better as ANYDTDTME32. even though there are only 21 or other lower number of characters involved.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.