This kind of problem looks like homework.
Here is thus an answer but you have to read documentation
about the "retain" statement to understand the first step which is calculating your results
http://support.sas.com/onlinedoc/913/getDoc/fr/lrdict.hlp/a000214163.htm
the second datastep is showing you that the result are in the table on the last observation
but understanding this step is not trivial and need a 'sum' of practice.
Andre
[pre]
data x;
infile cards ;
input id tot; retain one two 0;
if tot=1 then one+id;
if tot=2 then two+id;
cards;
5 1
6 2
7 .
5 1
6 2
9 .
run;
data _null_;
set x nobs=l point=l;
put one= two= ;
stop;
run;
[/pre]