I have a dataset with dates in one column. I have been using functions in Excel to extract the year and the month/day as two separate columns from the full date prior to importing the dataset into SAS, so the dataset looks like this once imported into SAS:
Full_Date Year Date Other Information
01JAN2012 2012 01/01 XYZ
03JUL2014 2014 07/03 ABC
26FEB2015 2015 02/26 DEF
We would like to instead be able to extract the year and date information and create these variables from the full_date directly in SAS after importing the file containing just the full date (and other info), without needing to first do the manipulation in Excel. So we would like to import the following, and make it look like the above dataset, all in SAS:
Full_Date Other Information
01JAN2012 XYZ
03JUL2014 ABC
26FEB2015 DEF
I know SAS has a YEAR function, but does a function exist to extract month/date in this fashion too? Thank you for any help.
If the variable comes into SAS as a date value (numeric with a format like date9.) then its as easy as:
year=year(full_date);
date = catx('/',put(month(full_date),z2.),put(day(full_date),z2.));
Date pretty much must be text as you're showing here.
You could also create a custom format to do this directly, Look up Proc Format and date predicates as an exercise for the interested reader.
If the variable comes into SAS as a date value (numeric with a format like date9.) then its as easy as:
year=year(full_date);
date = catx('/',put(month(full_date),z2.),put(day(full_date),z2.));
Date pretty much must be text as you're showing here.
You could also create a custom format to do this directly, Look up Proc Format and date predicates as an exercise for the interested reader.
Thank you, that works perfectly. Much appreciated!
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.
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.