第一次写按照SOC-PT分级的ADAE表格,在简书上记录下自己的思路,避免遗忘。
首先看一下AE表格的格式,发现第一列中包含了不同的层级。我的思路是分别对不同层级进行计数,最后汇总起来。
读取数据后,output一次,用来计算不分级的事件数和例数。
data adae1;
set ads.adae;
where SAFFL="是";
if AEBODSYS="" then AEBODSYS="未编码";
if AEDECOD="" then AEDECOD="未编码";
run;
data adae2;
set adae1;
output;
if saffl="是" then aebodsys="all";
output;
run;
之后通过排序去重,生成第一列的模板。并通过retain语句生成对模板排序用的序号。之后第一次合并dummy1_1 dummy2_1,将ord1添加到dummy2_1中,使得AEDECOD标记上了所对应的AEBODSYS。再将AEDECOD以及AEBODSYS添加到一列中,按照ORD1 ORD2排序后,就可以得到我们最终需要的模板了。
proc sort data=adae2 out=dummy1(keep=aebodsys) nodupkey sortseq=linguistic(locale=zh_CN collation=pinyin numeric_collation=on);
by aebodsys;
run;
proc sort data=adae1 out=dummy2(keep=aedecod aebodsys) nodupkey sortseq=linguistic(locale=zh_CN collation=pinyin numeric_collation=on);
by aebodsys aedecod;
run;
data dummy1_1;
set dummy1;
retain ord1 0;
by aebodsys;
ord1=ord1+1;
run;
data dummy2_1;
set dummy2;
retain ord2 0;
by aebodsys aedecod;
ord2=ord2+1;
if first.aebodsys then ord2=2;
run;
proc sql;
create table dummy_1 as select a.*,b.ord1 from dummy2_1 a left join dummy1_1 b on a.aebodsys=b.aebodsys;quit;
data dummy;
set dummy_1(keep=aedecod ord1 ord2 rename=(aedecod=name)) dummy1_1(keep=aebodsys ord1 rename=(aebodsys=name));
if ord2=. then ord2=1;
proc sort;
by ord1 ord2;
run;
之后我使用的是freq步来进行计数,得到对应AEBODSYS AEDECOD的频数。之后按照分组,整理成最终需要的样子。
proc freq data=adae2(where=(aebodsys="ALL")) noprint;
table aebodsys*trtan/out=count1(drop=percent) nopercent;
run;
proc freq data=adae2(where=(aebodsys^="ALL")) noprint;
table aebodsys*trtan/out=count2(drop=percent) nopercent;
run;
proc freq data=adae2(where=(aebodsys="ALL")) noprint;
table aedecod*trtan/out=count3(drop=percent) nopercent;
run;
%macro filter(indata=,outdata=,var=);
data temp1 temp2;
set &indata.;
if trtan=1 then output temp1;
if trtan=2 then output temp2;
run;
proc sort data=temp1(rename=(count=count1));
by &var.;
run;
proc sort data=temp2(rename=(count=count2));
by &var.;
run;
data &outdata.;
merge temp1 temp2;
by &var.;
if count1=. then count1=0;
if count2=. then count2=0;
rename &var.=col1;
drop trtan;
run;
%mend;
%filter(indata=count1,outdata=freq1,var=aebodsys);
%filter(indata=count2,outdata=freq2,var=aebodsys);
%filter(indata=count3,outdata=freq3,var=aedecod);
data freq;
set freq1-freq3;
proc sort;
by col1;
run;
对于例数,这个方案的定义是每个人每个SOC-PT发生的不良事件只计算一次。
所以排序得到每个受试者每个SOC-PT唯一不良事件记录后,按照上面的步骤得到例数。最后将例数除以各组受试者的数目,或者例数的百分比。最后将整理好的数据output成RTF文件即可。
proc sort data=adae2 out=adae3 nodupkey;
by subjid aebodsys aedecod ;
run;
proc freq data=adae3(where=(aebodsys="ALL")) noprint;
table aebodsys*trtan/out=count4(drop=percent) nopercent;
run;
proc freq data=adae3(where=(aebodsys^="ALL")) noprint;
table aebodsys*trtan/out=count5(drop=percent) nopercent;
run;
proc freq data=adae3(where=(aebodsys="ALL")) noprint;
table aedecod*trtan/out=count6(drop=percent) nopercent;
run;
%filter(indata=count4,outdata=freq4,var=aebodsys);
%filter(indata=count5,outdata=freq5,var=aebodsys);
%filter(indata=count6,outdata=freq6,var=aedecod);
data freq_;
set freq4-freq6;
proc sort;
by col1;
run;
data freq_all;
merge freq freq_(rename=(count1=count3 count2=count4));
by col1;
rename col1=col1_;
run;
data fin;
length col1-col5 $200;
set freq_all;
col1=col1_;
if count1=0 then col3="0";
else if count1>0 then col3=put(count1,3.);
if count2=0 then col2="0";
else if count2>0 then col2=put(count2,3.)||" ("||strip(put(100*count2/&bign1.,5.1))||")";
if count3=0 then col5="0";
else if count3>0 then col5=put(count3,3.);
if count4=0 then col4="0";
else if count4>0 then col4=put(count4,3.)||" ("||strip(put(100*count4/&bign2.,5.1))||")";
keep col1-col5;
run;
proc sql noprint;
create table final as select a.*,b.* from dummy a left join fin b on a.name=b.col1;
quit;
proc sort data=final;
by ord1 ord2;
run;
因为是第一次做,可能还存在一些问题,打算之后发现了再回来修正。