BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CedricLVQ
Calcite | Level 5

Hello all,

 

I am trying to import a csv file containing a datetime filled this way:

 

01/06/2018 21:45

 

where 01 is the day, then 06 the month, 2018 the year, 21 the hour and 45 the minute.

 

Unfortunately, by default SAS is using the ANYDTDTM16. informat which seems to be the US informat with the month filled before the day.

 

To do so, I used the following code:

 

PROC IMPORT DATAFILE="&Folder./&File" OUT=TempRH DBMS=CSV REPLACE;

DELIMITER=";";

INFORMAT Date_Heure datetime20.;

RUN;

 

 

 

Does anyone know how to import this correctly?

 

Thank you.

 

Cédric

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Try add an option. options datestyle=dmy;

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Does this generate an error? If yes, post the log. 

 

You can also import a csv file with the INFILE Statement in a data step. Tons of examples in here.

CedricLVQ
Calcite | Level 5

No error in the log, not even a warning but the import date time is 06JAN2018 21:45 instead of 01JUN2018 21:45

rudfaden
Pyrite | Level 9

ANYDTDTM also works with datetime values with day first

Kurt_Bremser
Super User

First of all, you are more intelligent than a few grams of silicone, so it's time for you to take over.

Take the data step code created and run by proc import from the log, and adapt it. Read the datetime value into a string, dissect it into its two parts with scan(), input the first part with ddmmyy10., the second with time8., and then build your datetime value with the dhms() function.

want = dhms(input(scan(string,1),ddmmyy10.),0,0,input(scan(string,2),time5.));
format want e8601dt19.;
CedricLVQ
Calcite | Level 5

Thank you for you help.

 

My colleague advised me to use this trick but it seems that adding:

 

options datastyle=dmy works.

 

 

Ksharp
Super User
Try add an option. options datestyle=dmy;
CedricLVQ
Calcite | Level 5

Wouah, thanks, that works great!

Ksharp
Super User

Try add an option.

 

options datestyle=dmy;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 10581 views
  • 0 likes
  • 5 in conversation