The following code gives the answer og Q1.1. For Q1.2 and 2 another variable need to be created in the select statement.
Then do the calculation in the data step for testdata_4.
Please note, an observation was added at the end of data.
data testdata_1;
input p $ C $ qt;
cards;
a a1 7
a a2 5
a a3 12
a a4 10
a a5 9
b b1 9
b b2 6
b b3 10
b b4 8
c c1 2
c c2 5
c c3 0 /* I added the obs */
;
run;
proc print data=testdata_1; run;
data testdata_2;
set testdata_1;
select (c);
when ('a1') AProd=int(qt/1);
when ('a2') Aprod=int(qt/1);
when ('a3') Aprod=int(qt/2);
when ('a4') Aprod=int(qt/2);
when ('a5') Aprod=int(qt/1);
when ('b1') Aprod=int(qt/1);
when ('b2') Aprod=int(qt/1);
when ('b3') Aprod=int(qt/2);
when ('b4') Aprod=int(qt/1);
when ('c1') Aprod=int(qt/2);
when ('c2') Aprod=int(qt/1);
when ('c3') Aprod=int(qt/2);
otherwise;
end;
run;
proc print data=testdata_2; run;
proc sort data=testdata_2 out=testdata_3;
by p Aprod;
run;
proc print data=testdata_3; run;
data testdata_4;
set testdata_3;
by p;
if first.p;
keep p aprod;
run;
ods pdf file="D:\Mysas\SASData\Tempresults\Q1_1_Answer.pdf";
title 'Number of Product Can Be Built';
proc print data=testdata_4 noobs label;
label p = 'Product'
aprod = 'Quantity';
run;
ods pdf close;
[此贴子已经被作者于2009-1-14 6:39:55编辑过]