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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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