Hi everyone.
I'm wondering how can I generate the variable final given I have the dataset with variable id, flag and total more elegantly than what I've done(below)?
Thank you very much and happy Easter!
id flag total final
1 0 4 3
1 . 4 3
1 . 4 3
1 1 4 3
2 1 2 2
2 . 2 2
3 . 5 2
3 1 5 2
3 0 5 2
3 0 5 2
3 0 5 2
4 . 1 1
5 . 2 2
5 . 2 2
My code is:
data b;
set a;
by id;
retain total2 0;
if first.id then total2=total;
if flag=0 then total2=total2-1;
run;
proc sql;
select *, min(total2) as final
from b
group by id;
quit;