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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.