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
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;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: