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

Strange date format

Status
Not open for further replies.

Medvedeff

Instructor
Feb 12, 2008
29
0
0
US
I currently have a raw data extract with the dates in a strange format, and I am not quite sure how to work with them. Their current format is as follows:

2008/8/28 12:00AM

I need to be able to clean the data based on the month and year of the observation, but SAS reads this format as $18 and I dont know how to get it into a better format so that I can work with it.

Any ideas? Thanks in advance.
 
If you don't need the time portion its really simple to work with this type of date. SAS dates (not datetime values) are the number of days from Jan 1, 1960. This means that if you can convert the date portion into a SAS date value you can use all the SAS date functions (such as MONTH(), YEAR() etc...)

You state that you read in this date as a Char $18 string. Keep doing that and once you read this in that format all you have to do is use the SCAN() and INPUT() functions.

example
Code:
data yourdata;
 *** datevalue='2002/8/28 12:00PM'  ****;

 *** SCAN THE DATE PORTION  ***;
 dateportion = scan(datevalue,1,' ');
 sasdate     = input(dateportion,yymmdd10.);

 *** NOW USE THE SAS FUNCTIONS MONTH(), YEAR() ON THE SASDATE VARIABLE ***;

run;

Good luck!

Klaz
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top