BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmaths
Calcite | Level 5


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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

kmaths
Calcite | Level 5

Thank you, that works perfectly. Much appreciated!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 41877 views
  • 2 likes
  • 2 in conversation