You could try using Array() to first get the number: data check3; infile datalines dlm=','; input defect1 defect2 defect3; datalines; 0,0,0 1,0,0 1,2,0 5,0,1 0,0,0 0,1,0 0,0,0 5,0,0 0,0,9 0,0,0 ; data want (drop=defect:); set check3 end=last nobs=nobs; array df (*) _numeric_; do _n_=1 to dim(df); d1+ifn(df(_n_)=1,1,0); d2+ifn(df(_n_)=2,1,0); d5+ifn(df(_n_)=5,1,0); end; if last then do; d1_rate=d1/nobs; d2_rate=d2/nobs; d5_rate=d5/nobs; output; end; run; proc print;run; Regards, Haikuo Edit to add the ratio.
... View more