I have a data set where an observation can be a part of multiple groups within a variable. The variable has four options coded as 'red', 'green', 'yellow', 'white'. Observations with multiple are coded as group, group, ...etc. for example 'red, green'. When I run proc freq, proc freq sees this as 5 groups. I want to be able to have the multiple observation count into each respective group so for the example 'red, green' it adds a count to red and one to green instead of being run as it's own group. %macro disc_tab (dset, var,grp1,grp2,ct,ct1,ct2,ct3,ct4,ctc,name,ord);
proc sort data= &dset out=sort1&dset;
by &grp1;
proc freq data= sort1&dset;
table &var/out =outtot&var sparse;
where &var ne '';
proc freq data=sort1&dset;
table &var/out=out1&var sparse;
where &var ne '';
by &grp1;
proc sort data= &dset out=sort2&dset;
by &grp2;
proc freq data=sort2&dset;
table &var/out=out2&var sparse;
where &var ne '';
by &grp2;
data outtot&var;
set outtot&var;
npc=trim(left(count))||"/&ct ("||trim(left(put(percent,5.1)))||')';
data out1&var;
set out1&var;
if subcoh =1 then npc=trim(left(count))||"/&ct1 ("||trim(left(put(percent,5.1)))||')';
if subcoh =2 then npc=trim(left(count))||"/&ct2 ("||trim(left(put(percent,5.1)))||')';
if subcoh =3 then npc=trim(left(count))||"/&ct3 ("||trim(left(put(percent,5.1)))||')';
if subcoh =4 then npc=trim(left(count(*)))||"/&ct4 ("||trim(left(put(percent,5.1)))||')';
data out2&var;
set out2&var;
if comb =0 then npc=trim(left(count))||"/&ct1 ("||trim(left(put(percent,5.1)))||')';
if comb =1 then npc=trim(left(count))||"/&ctc ("||trim(left(put(percent,5.1)))||')';
data out&var;
set outtot&var out1&var out2&var;
proc SORT;
BY &var;
PROC TRANSPOSE data=out&var out=trans&var;
VAR npc;
BY &var;
run;
Data table&var;
length stat $300.;
FORMAT stat var $300.;
set trans&var;
stat=&var;
drop COL6 ;
var=&name;
ord=⩝
run;
%mend disc_tab;
%disc_tab(mh_analysis,mhterm2_display,subcoh,comb,&n_term2,&n1_term2,&n2_term2,&n3_term2,&n4_term2,&nc_term2,'color* [N (%)]',3);
... View more