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

Hi,

 

I have a column contains date information (MM/DD/YYYY) as below. How do I create a new column that only contains the "year" from this column? For example, the first row of the new column is 2015, and  the next two rows are 2018.

 

Date

08/18/2015
01/15/2018
10/01/2018

 

Thank you all in advance! 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If these are NUMERIC date values then this should work

 

data want;
     set have;
     year=year(date);
run;

If these are CHARACTER date values

 

data want;
     set have;
     date=input(date,mmddyy10.);
     year=year(date);
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If these are NUMERIC date values then this should work

 

data want;
     set have;
     year=year(date);
run;

If these are CHARACTER date values

 

data want;
     set have;
     date=input(date,mmddyy10.);
     year=year(date);
run;
--
Paige Miller
ballardw
Super User

What will you use that Year value for?

In many cases if the value is an actual SAS date value you would just assign the Year. format for many things.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 737 views
  • 0 likes
  • 3 in conversation