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: 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!

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.

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