Hi, Try: data have; attrib p format=$20. m1-m4 format=best.; infile datalines delimiter=','; input p $ m1-m4; datalines; 1,8,1,., 9 2,.,.,3,15 3,4,5,.,12 4,1,.,.,10 ; quit; proc sql; create table OUTPUT1 ( MONTH1INTERSECTMONTH2 num, MONTH2INTERSECTMONTH3 num, MONTH3INTERSECTMONTH4 num ); create table OUTPUT2 ( MONTH2INTERSECTMONTH1 num, MONTH3INTERSECTMONTH21 num, MONTH4INTERSECTMONTH321 num ); insert into OUTPUT1 set MONTH1INTERSECTMONTH2=(select count(P) from WORK.HAVE where M1 is not null and M2 is not null), MONTH2INTERSECTMONTH3=(select count(P) from WORK.HAVE where M2 is not null and M3 is not null), MONTH3INTERSECTMONTH4=(select count(P) from WORK.HAVE where M3 is not null and M4 is not null); insert into OUTPUT2 set MONTH2INTERSECTMONTH1=(select count(P) from WORK.HAVE where M2 is not null and M1 is not null), MONTH3INTERSECTMONTH21=(select count(P) from WORK.HAVE where M3 is not null and (M2 is not null or M1 is not null)), MONTH4INTERSECTMONTH321=(select count(P) from WORK.HAVE where M4 is not null and (M3 is not null or M2 is not null or M1 is not null)); quit;
... View more