Or you could use this after the initial read in: data have2; set have; array mon (4) m1-m4; array moni (3) mi1-mi3; do i = 1 to 3; if mon(i) ~=. and mon(i+1)~=. then moni(i) = 1; else moni(i) = 0; end; run proc sql; create table want as select distinct sum(mi1) as mi1, sum(mi2) as mi2, sum(mi3) as mi3, sum(case when m2~=. and m1 ~=. then 1 else 0 end) as m2mi1, sum(case when m3~=. and (m1~=. or m2~=.) then 1 else 0 end) as m3mi12, sum(case when m4 ~=. and (m1~=. or m2 ~=. or m3 ~=.) then 1 else 0 end) as m4mi123 from have2; ;
... View more