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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1163 views
  • 1 like
  • 2 in conversation