Desktop productivity for business analysts and programmers

how to do an average for a value over months in SAS enterprise guide?

Reply
Occasional Contributor
Posts: 10

how to do an average for a value over months in SAS enterprise guide?

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

Respected Advisor
Posts: 4,795

Re: how to do an average for a value over months in SAS enterprise guide?

Posted in reply to salamabdeen

@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;
Ask a Question
Discussion stats
  • 1 reply
  • 107 views
  • 0 likes
  • 2 in conversation