DATA Step, Macro, Functions and more

importing sas datetime

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 101
Accepted Solution

importing sas datetime

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,

 


Accepted Solutions
Solution
‎03-15-2017 04:37 PM
Super User
Posts: 6,972

Re: importing sas datetime

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,972

Re: importing sas datetime

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,430

Re: importing sas datetime

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

Frequent Contributor
Frequent Contributor
Posts: 101

Re: importing sas datetime

proc import datafile='test.csv' out=data dbms=csv replace;
getnames=yes;
datarow = 2;
run;
Solution
‎03-15-2017 04:37 PM
Super User
Posts: 6,972

Re: importing sas datetime

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Frequent Contributor
Posts: 101

Re: importing sas datetime

@KurtBremser

Thanks. it worked.

Super User
Super User
Posts: 7,430

Re: importing sas datetime

Yes, as @KurtBremser 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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 141 views
  • 2 likes
  • 3 in conversation