From: atulrill on

Hi,
I have a query related to SAS enterprise guide ,i need a sql
code to find out average as mentioned in below table. there are three
variables Time Flag demand, so i need average of demand when timeflag
=0-9 then when time flag = 10-18 then average of demand , when time
flag = 19-22 then average of demand and when time flag = 22-24 then
average of demand as shown in table below.so i need a code using CASE
in filter or code in Sql or data set.I need it urgently so please help

Time Flag Demand Average
0 18.0 13.1
1 20.0
2 11.0
3 15.0
4 16.0
5 17.0
6 5.0
7 4.0
8 8.0
9 17.0 24.9
10 16.0
11 19.0
12 20.0
13 21.0
14 22.0
15 30.0
16 31.0
17 32.0
18 33.0 20.5
19 34.0
20 35.0
21 36.0
22 37.0 23.0
23 38.0
24 39.0

Thanks
Atul
From: shiva on
Hi Atul..

Try this...

proc format ;
value temp
0-9='A'
10-18='B'
19-21='C'
22-24='D'
;
run;
data test;
input TIme FlagDemand ;
line = put(time,temp.);
cards;
0 18.0
1 20.0
2 11.0
3 15.0
4 16.0
5 17.0
6 5.0
7 4.0
8 8.0
9 17.0
10 16.0
11 19.0
12 20.0
13 21.0
14 22.0
15 30.0
16 31.0
17 32.0
18 33.0
19 34.0
20 35.0
21 36.0
22 37.0
23 38.0
24 39.0
run;
proc sql;
create table te as
select time ,flagdemand,avg(flagdemand)as avg ,line
from test
group by line;
quit;


Thanks,
Shiva
From: shiva on
Hi Atul..

Try this...

proc format ;
value temp
0-9='A'
10-18='B'
19-21='C'
22-24='D'
;
run;
data test;
input TIme FlagDemand ;
line = put(time,temp.);
cards;
0 18.0
1 20.0
2 11.0
3 15.0
4 16.0
5 17.0
6 5.0
7 4.0
8 8.0
9 17.0
10 16.0
11 19.0
12 20.0
13 21.0
14 22.0
15 30.0
16 31.0
17 32.0
18 33.0
19 34.0
20 35.0
21 36.0
22 37.0
23 38.0
24 39.0
run;
proc sql;
create table te as
select time ,flagdemand,avg(flagdemand)as avg ,line
from test
group by line;
quit;


Thanks,
Shiva