Hi guys, anyone can help me to simplify my code in the way to format my final dataset want?...maybe using loops rather than write down by hand the 4 combinations (class/type)? data new; input name class $ type $; datalines; 1 a yes 2 a no 3 a yes 4 b no 5 b yes 6 a yes 7 b no 8 b no 9 b yes 10 a yes 11 a yes ; run; *creating macrovariables; proc sql noprint; select count(distinct name) into: safea from new where class='a'; quit; proc sql noprint; select count(distinct name) into: safeb from new where class='b'; quit; %put &safea; %put &safeb; proc sql noprint; create table test as select distinct class, type, count(distinct name) as n from new group by class,type; quit; *creating the format of my want dataset; data want; set test; if class='a' and type='yes' then nc=put(n,best12.)||'('||put(n/&safea*100,5.1)||')'; if class='a' and type='no' then nc=put(n,best12.)||'('||put(n/&safea*100,5.1)||')'; if class='b' and type='yes' then nc=put(n,best12.)||'('||put(n/&safeb*100,5.1)||')'; if class='b' and type='no' then nc=put(n,best12.)||'('||put(n/&safeb*100,5.1)||')'; drop n; run; Thanks V.
... View more