DATA Have; Length Variable $ 20 ID $ 10 Missing 8 Grade1 8 Grade2 8 Grade3 8; Infile Datalines Missover ; Input Variable ID Missing Grade1 Grade2 Grade3; Datalines; Variable1 0001 0 0 1 0 Variable1 0001 0 1 0 0 Variable1 0002 0 0 0 1 Variable1 0002 0 0 1 0 Variable1 0003 0 1 0 0 Variable1 0003 0 0 0 1 Variable2 0001 0 1 0 0 Variable2 0001 0 1 0 0 Variable2 0002 0 0 1 0 Variable2 0002 0 0 0 1 Variable2 0003 0 0 0 1 Variable2 0003 0 0 1 0 Variable3 0001 0 1 0 0 Variable3 0001 0 1 0 0 Variable3 0002 0 0 1 0 Variable3 0002 0 0 0 1 Variable3 0003 0 0 1 0 Variable3 0003 0 0 0 1 ; Run; PROC SQL; CREATE TABLE Want AS SELECT have.Variable, (SUM(Grade1)) AS Count1 ,calculated Count1/Sum as Percent1 format=percent8.2 ,(SUM(Grade2)) AS Count2 ,calculated Count2/Sum as Percent2 format=percent8.2 ,(SUM(Grade3)) AS Count3 ,calculated Count3/Sum as Percent3 format=percent8.2 ,(SUM(Missing)) AS CountM ,calculated CountM/Sum as PercentM format=percent8.2 ,(COUNT(DISTINCT(ID))) AS CountT ,calculated CountT/Sum as PercentT format=percent8.2 FROM Have, (Select variable, count(*) as sum from have group by variable) as have2 where have.variable=have2.variable GROUP BY have.Variable; QUIT; proc print data=want; run;
Obs
Variable
Count1
Percent1
Count2
Percent2
Count3
Percent3
CountM
PercentM
CountT
PercentT
1
Variable1
2
33.33%
2
33.33%
2
33.33%
0
0.00%
3
50.00%
2
Variable2
2
33.33%
2
33.33%
2
33.33%
0
0.00%
3
50.00%
3
Variable3
2
33.33%
2
33.33%
2
33.33%
0
0.00%
3
50.00%
... View more