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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV DATE FORMAT 1

Status
Not open for further replies.

ctse

Technical User
May 19, 2009
10
AU
Hi,

I am importing a csv file with date stamp and time stamp into SAS. In my csv (text) file, I have a column titled date with the date format DD-MMM-YYYY (e.g., 20-May-2008). When I import this file in SA, the date stays the same as above (i.e. 20-May-2008) but when I look at either its format or informat for date I see $11.

I tried changing the format to a date format in SAS but with no success. I want to be able to convert this into a date format to do some calculations.

Similarly, I also have another separate column in the same csv that stores time in the format HH:MM:SS.LLL (e.g., 13:29:54.164). I see the same thing in SAS but the format is now $12.

Again, I tried converting this to a time format but SAS keeps coming up with error messages (invalid format, etc).

In summary, how can I format the date back to DD-MMM-YYYY and time to HH:MM:SS.LLL I know it may be a simple question but I am learning SAS day by day so I appreciate the help.

Cheers,

C+
 
Why not use the INPUT function. While you could do this at time of import, my suggestion is to convert the values in the next step. This way you have both the 'TEXT' version and the SAS numeric version of those values.

I am presuming that your data values is in a variable named MYDATE and your time value is in variable named MYTIME.

NOTE: always rememember that SAS keeps date values as the number of days from 1/1/1960. Time values as the number of seconds in the day and DATETIME values as the number of seconds from 1/1/1960.

Code:
data mydata;
   set yourdatathatuimported;
   MyNewSASDate = INPUT(MYDATE, DATE9.);
   MyNewSASTime = INPUT(MYTIME, time8.);
   *** IF YOU NEED THE THOUSANDS USE time12. ***;

   *** THE REST OF YOUR CODE ***;
run;

I hope this helps.
Klaz
 
Thanks Klaz.

It worked perfectly!

c+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top