Help using Base SAS procedures

Converting dates from text format

Not applicable
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?

Super Contributor
Super Contributor
Posts: 3,176

Re: Converting dates from text format

Posted in reply to deleted_user
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 link to related DOC for your reference (mind any broken URL string):

SAS 9.2 DOC - About SAS Date, Time, and Datetime Values

more of the same topic discussion at the link below:

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 183

Re: Converting dates from text format

Posted in reply to deleted_user
data test;
dates_txt = '20oct2008';
dates_sd = input(dates_txt,date9.); put dates_sd= date.;
month = month(dates_sd);
year = year(dates_sd);

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
  • 3 in conversation