Hi all,
I'm currently using SAS Enterprise Guide 7.1 for one of my classes and I'm having a tough time grouping these date variables. I have a dataset ranging from 2015 to 2020. The Date column is listed as:
01JAN2015
01FEB2015
01MAR2015
01APR2015
01MAY2015
...(and so on)...
01SEP2020
01OCT2020
01NOV2020
I'm trying to group these into separate year – how would I do that? I tried using the recoding column, but I'm guessing that the format needs to be changed from .DATE9 to something else (?) Any ideas/suggestions? Thank you 🙂
HI @adriannek You could use the YEAR function to create a new variable and group by
Alternatively, in a PROC you could use YEAR4. format.
Example-
data have;
input date :date9.;
format date date9.;
cards;
01JAN2015
01FEB2015
01MAR2015
01APR2015
01MAY2015
01SEP2020
01OCT2020
01NOV2020
;
proc sql;
select year(date) as year, count(*) as count
from have
group by year;
quit;
/*Or*/
proc summary data=have nway;
class date;
format date year4.;
output out= want(drop=_type_);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.