Hi Community,
I have a long dataset while there are multiple records per id. I want to create a dataset and it is one record per id under the conditions as:
if condition a=1, then under the condition b=0, get a total sum of d. When the last id, use that total sum to be divided by e to get f and output.
I have test the codes using a single id is fine (where statement),however, if I use it into more ids, the answer is wrong. There are somethings I miss in the codes. Or please suggest a better way to do it. Your suggestion is appreciated.
data want; set have;*sorted; by id; retain total;
/*where id =aa;*/ if a=1 then do; if b = 0 then do; if first.id then total=d; else total=sum(total,d); end;
if last.id then do; f=total/e; output; end; end; run;
... View more