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.
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 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.