Help using Base SAS procedures

Converting dates from text format

Reply
N/A
Posts: 0

Converting dates from text format

In my dataset, dates are stored in text as daymonthyear, where "day" is the date in two digits, "month" is 3-letter abbreviation for the month, and "year" is the 4-digit year. I want to retain month and year in a date or numeric format to ease comparison of data across months. What is the most efficient way to do this?

Thanks!
Super Contributor
Super Contributor
Posts: 3,174

Re: Converting dates from text format

The most effective approach within the SAS system is to assign DATE and / or DATETIME SAS (numeric) variables. So, then using these numeric variables, you can display them in various formats, while still being able to compare and calculate differences and such with the numeric SAS variable (which are stored internally as days since 1/1/1960 or seconds since 1/1/1960).

I have provided a SAS support website http://support.sas.com/ link to related DOC for your reference (mind any broken URL string):

SAS 9.2 DOC - About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/59522/HTML/default/a002200738.htm

more of the same topic discussion at the link below:
http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_intervals_sect014.htm

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 160

Re: Converting dates from text format

data test;
dates_txt = '20oct2008';
dates_sd = input(dates_txt,date9.); put dates_sd= date.;
month = month(dates_sd);
year = year(dates_sd);
run;

Store your dates as numeric variables (ie. the result of dates_sd), then you can use all the many SAS date functions and formats.
Ask a Question
Discussion stats
  • 2 replies
  • 133 views
  • 0 likes
  • 3 in conversation