Use Scott's links to understand the following:
[pre]data OUT;
input PAT_ID MONTH1 MONTH2 MONTH3; * can be written input PAT_ID (MONTH1-MONTH3)(:);
if MONTH1 then do;
MONTH1=sum(of MONTH1-MONTH3);
call missing(MONTH2, MONTH3);
end;
else if MONTH2 then do;
MONTH2=sum(of MONTH1-MONTH3);
call missing(MONTH1, MONTH3);
end;
else if MONTH3 then do;
MONTH3=sum(of MONTH1-MONTH3);
call missing(MONTH1, MONTH2);
end;
else call missing(of MONTH1-MONTH3);
cards;
1 0 1 2
2 1 1 2
3 2 0 1
4 0 0 3
5 3 0 0
6 0 0 2
7 0 2 0
8 0 2 2
;
run;
[/pre]
If you had many months, you'd loop thru them using an array, as Scott said, rather than adding tests.
One step at a time though.