BookmarkSubscribeRSS Feed
salamabdeen
Fluorite | Level 6

Hello!

I need to compute an average value of (energy) over the year for each center alone, I already tried to use functions like:

 case

 when FIND(CENTER , 'center1')

 THEN AVG(energy)

 

But it didn't work, because it considering every record individually.

Any one has an idea?

 

Thanks

1 REPLY 1
Patrick
Opal | Level 21

@salamabdeen

You're looking for the SQL Group By statement.

data work.have;
    format
        center           $char7.
        month            date9.
        energy           comma12. ;
    infile datalines4
        dlm='7f'x
        missover
        dsd ;
    input
        center           : $char7.
        month            : best32.
        energy           : best32. ;
datalines4;
Center120820948275
Center220820969198
Center320820985288
Center120851100
Center220851995577
Center320851786347
Center120879837422
Center220879926075
Center320879953334
Center12091098728
Center220910100
Center320910978923
Center120940100
Center220940822499
Center320940996982
Center120971993588
Center220971951744
Center320971991644
Center121001100
Center221001901471
Center321001924098
Center121032100
Center22103299098
Center321032100
Center12106395625
Center22106399321
Center321063999274
Center121093448723
Center221093100
Center321093903513
Center121124746435
Center221124842469
Center321124889007
Center121154100
Center22115481134259259
Center32115492904905914
;;;;
run;

proc sql;
  create table want as
  select 
    center,
    year(month) as year,
    avg(energy) as avg_energy format=comma12.
  from have
  group by center, year
  ;
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1053 views
  • 0 likes
  • 2 in conversation