Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

importing timestamp from csv 1

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
I have a csv with date and time combined in the following format mm/dd/yyyy hh:mm:ss. I want to import this file into SAS and get it into a format SAS can recognize so I can do some manipulation based on date. My the closest I can get is this:

informat timecolumn DATETIME;

or this
informat timecolumn MMDDYY10.;

But neither seem to give me the whole date and time combined.

any tips?
 
I presume that when you mean CSV, you mean that the data is text and not a date value. (The reason I announce this fact is that Excel saves the datetime values as the number of seconds from jan 1 1970, while SAS saves the number of seconds from jan 1 1960. When you use the SAS Proc import it should convert the value for you.)

That stated, if your CSV data is text, then read the text in and convert the text to a SAS datetime value.

ex of the conversion
Code:
datavalue = yourCSVdate;
convertedvalue =input(put(input(scan(datavalue,1,' '),mmddyy10.),date9.)||':'||scan(datavalue,2,' '),datetime20.);

You should now have the SAS equiv of the datetime value. The datetime informat needs the date to be in the month name format. In the above example I read the first part of the string (using the SCAN function) and convert that to the month name format.

Hope that this helps you.
Klaz
 
That seems to do the trick. Thanks. Any good resources you could recommend that explains all the behind the scenes and in front of the scenes dates stuff?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top