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
Lapis Lazuli | Level 10

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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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