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;
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.