BookmarkSubscribeRSS Feed
tsetredst
Calcite | Level 5

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!

3 REPLIES 3
Reeza
Super User

Try an informat of anydtdm21 and a format of datetime21

tsetredst
Calcite | Level 5

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

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 1029 views
  • 0 likes
  • 3 in conversation