BookmarkSubscribeRSS Feed
adriannek
Calcite | Level 5

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 🙂  

1 REPLY 1
novinosrin
Tourmaline | Level 20

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

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.

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
  • 1 reply
  • 747 views
  • 1 like
  • 2 in conversation