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!
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.