BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
GertNissen
Barite | Level 11
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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1175 views
  • 0 likes
  • 3 in conversation