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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1319 views
  • 0 likes
  • 2 in conversation