data dmy01;
length cat2_colname $200.;
id1=1;id2=0;cat2_colname="COMALL";output;
ID1;ID2=1;cat2_colname="COM1";output;
ID1;ID2=2;cat2_colname="COM2";output;
run;
data dmy;
set dmy_01;
if col2_colname="CCIFL" then val=ID2;
else val=1;
output;
run;
%macro dt_set;
data base;
length subjid;
merge adsl(in=x keep=SUBJID COHRT_: where=(&prrf A%if &cond.^=%str() %then %do;and &cond. %end;))
;
by subjid;
if x;
drop cci:;
run;
data base_wk01;
set
%if &inc_type=1 %then %do;
%let where1=%str(SCOHRT_11=1);
%let where1=%str(SCOHRT_12=1);
%let where1=%str(SCOHRT_13=1);
%end;
%if &inc_type=3 %then %do;
%let where1=%str(SCOHRT_31=1);
%let where1=%str(SCOHRT_32=1);
%let where1=%str(SCOHRT_33=1);
%end;
%if &inc_type=5 %then %do;
%let where1=%str(SCOHRT_51=1);
%let where1=%str(SCOHRT_52=1);
%let where1=%str(SCOHRT_53=1);
%end;
base(in=a where=(&where1. or &where2.))
base(in=b where=(&where1. ))
base(in=c where=(&where2.))
base(in=d where=(&where3.))
;
if a then cat1=1;
if b then cat1=2;
if c then cat1=3;
if d then cat1=4;
run;
proc sort data=base_wk01 out=base_wk01_s ;by subjid cat1;run;
proc transpose data=base_wk01_s out=base_tran(where=(val1^=.) drop col2) prefix=val;
var com1-com11 elix-elix33
;
by subjid cat1;
run;
data base_tran_01;
length cat2_collabel col2_colname $200.;
set
base_tran(in=a)
base_tran(in=b)
;
if a then do;
cat2=1;
if index(_NAME_,"COM")>0 then do;
cat2_colname="COM_ALL";
cat2_colname="COM_ALL";
end;
if index(_NAME_,"Elix")>0 then do;
cat2_colname="Elix_ALL";
cat2_colname="Elix_ALL";
%end;
%end;
if b then do;
cat2=2;
cat2_collabel=_LABEL_;
cat2_colname=_NAME_;
end;
if index(_NAME_,"COM")>0 then do;
ID1=1;
end;
cat2=1;
if index(_NAME_,"Elix")>0 then do;
ID1=2;
end;
end;
run;
*データ部分集計;
data base_tran_01;
val=val1;
run;
proc sort data=base_tran_01_x;by val cat1 id1 cat2 cat2_colname col2_collabel;run;
proc means data=base_tran_01_s noprint;
var val1;
output out=means n=N MEAN=MEAN STD=StD MEDIAN=MED;
by val cat1 id1 cat2 cat2_colname col2_collabel;
run;
data means_01;
set means;
rename val1=value;
if cat2_colname^="DDIFL" and val=0 then delete;
run;
proc sort data=means_01;by id1 cat1 val;run;
proc sort data=means_01; out=mean_02_1(where(cat2=1 and cat2_coluname^=CCIFL_ALL") rename N=ALL_COUNT keep cat2 id1 val cat1 N cat2_colname);
by id1 cat1 val;run;
proc sort data=means_01; out=mean_02_1(where(cat2=1 and cat2_coluname=CCIFL_ALL") rename N=ALL_COUNT keep cat2 id1 val cat1 N cat2_colname);
by id1 cat1 val;run;
data means_03_1;
merge means_01
means_02_1(in=x)
;
by id1 cat1 val;
if x;
run;
data means_03_2;
merge means_01
means_02_2(in=x)
;
by id1 cat1 ;
if x;
run;
proc sort data=means_03;by id1 cat2_colname val;run;
proc sort data=dmy;by id cat2_colname val;run;
data res001;
length _col1-_col2 $200.;
merge dmy(in=x)
means_03
;
if x;
by id1 cat2_colname val;
if cat2=1 then do;
if cat2_colname="CCIFL_ALL" then
do;
if N^=.then _col1=strip(put(round(mean,0.1)8.1))||"±"||strip(put(round(std,0.01),8.2))||"["||strip(put(round(med,0.1)8.1))||"]";
else _col1="-";
end;
else do;
_Col1="";
_COl2="";
end;
end;
else do;
if N^=. then
_col1=strip(put(n,comma8.));
else
_col1="=";
if ALL_COUNT^=. then
_col2=strip(put(round(n/all_count*100,0.1)8.1));
else
_col2="-";
end;
run;
data res02;
merge
res01(where=cat1=1)
res01(where=cat1=1 rename=_col1=_col3 _col2=_col4)
res01(where=cat1=1 rename=_col1=_col5 _col2=_col6)
res01(where=cat1=1 rename=_col1=_col7 _col2=_col8)
;
by id1 cat2_colname val;
run;
proc sort data=dmy;by id1 id2 val;run;
proc sort data=res02;by id1 id2 val;run;
data res03;
merge dmy(in=x)res02;
by id1 id2 val;
if cat2=. then do;
_col1="-";
_col2="-";
end;
run;
*合計部分集計;
proc sort data=base_tran_01 out=base_tran_01_nod nodupkey;by CAT1 SUBJID;run;
proc sql
create table means_all as
select
sum(case when cat1=1 then 1 else 0 end) as _COL1_dmy
%do i=1 %to &end_col./2;
,strip(put(sum(case shen cat1=&i then 1 else 0 end),comma8.)) as _col%eval(&i*2-1)
,"" as _col%eval(&i+2)
%end;
from base_tran_01_nod
;
quit;
data means_all01;
length _col1-col&end_col.$200.;
%if &sqlobs=0 5then %do;
set Means_ALL;
%end;
array dt _col1-_col&end_col.;
do i=1 to &end_col.;
if dt(i) ^="" then dt(i)="N="||dt(i);
end;
run;
*集計のセット;
data dmy_nper;
length _col1-col&end_col.$200.;
arrray dt _col1-col&end_col;
do i=1 to %eval(&end_COL./2);
dt(i*2-1)="N";
dt(i*2)="%";
end;
run;
%mend;
%sht_output(M_T3_1,1,r6c6:R200C%eval(&end_col+6),col1-col&end_col,1,%nrstr(cohrt_1=1));