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

I am trying to import a csv file with datetime variable in the form 

2011-02-02T15:22

 

But when the data is imported, only date remains like this

 

2011-02-02

 

Any help to import the datetime variable correctly?

 

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Copy the data step from the log (proc import writes the data step it creates to the log) and adapt the informat for the column in question.

Then re-run the data step.

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Use the e8601dt informat, as in

data test;
string = "2011-02-02T15:22";
dtval = input(string,e8601dt19.);
format dtval datetime19.;
put dtval=;
run;

 You can use that informat directly in the input statement.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post the import code (into a {i}) so we can see how you are importing it.

ari
Quartz | Level 8 ari
Quartz | Level 8
proc import datafile='test.csv' out=data dbms=csv replace;
getnames=yes;
datarow = 2;
run;
Kurt_Bremser
Super User

Copy the data step from the log (proc import writes the data step it creates to the log) and adapt the informat for the column in question.

Then re-run the data step.

ari
Quartz | Level 8 ari
Quartz | Level 8

@Kurt_Bremser

Thanks. it worked.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, as @Kurt_Bremser has stated, use a datastep import and set the columns yourself.  Proc import is a guessing procedure - i.e. it is guessing what your data is.  Never a good idea.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 2665 views
  • 2 likes
  • 3 in conversation