AE蝴蝶圖紀(jì)錄

參考資料:《Amazing Graph Series: Butterfly Graph Using SGPLOT and GTL》,可以在www.pharmasug.org網(wǎng)站上下載。

f_butterfly.png

摸魚時看到一篇關(guān)于蝴蝶圖的文章,跟著寫一遍順便紀(jì)錄下來,數(shù)據(jù)集會附在最后。

**  options set  **;
ods escapechar="^";
ods _all_ close;
options ls=max;

**  create template  **;

proc template;
  define statgraph fly;
  begingraph;
  entrytitle "Summary of Most Frequent TEAEs (>=10% of Total) by Treatment and Toxicity Grade";
  entryfootnote halign=right "Data Extraction Date: &sysdate.T&systime.";
**  定義圖例的顏色以及對應(yīng)的變量  **;
    discreteattrmap name="name";
    value "Grade 1" / fillattrs=(color=CADETBLUE);
    value "Grade 2" / fillattrs=(color=bib);
    value "Grade 3" / fillattrs=(color=red);
    value "Grade 4" / fillattrs=(color=purple);
    enddiscreteattrmap;
  discreteattrvar attrvar=MYID_GRD var=grade attrmap="name";

**  定義布局,為左中右式布局  **;
  layout lattice / rowdatarange= union columnweights= (0.42 0.16 0.42) columns=3;
**  定義左側(cè)  **;
  layout overlay / walldisplay=none
**  定義X軸范圍 網(wǎng)格線  Y軸不顯示**;
  xaxisopts=(tickvalueattrs=(size=7)
  display=(line tickvalues) griddisplay=on
  reverse=true linearopts=(viewmin=0 viewmax=70 
  tickvaluesequence=(start=0 end=70 increment=10)))

  yaxisopts=(display=none reverse=true);
**  定義柱子屬性  **;
  barchart category=aedecod response=_1/
  group=myid_grd name="bar1"
  orient=horizontal dataskin=pressed segmentlabel=true segmentlabelattrs=(color=white);
  entry "Treatment 1 (N=&n1.)" / autoalign=(bottomleft);
  endlayout;

**  定義中間部分  **;
  layout overlay / xaxisopts=(display=none) walldisplay=none yaxisopts=(display=(tickvalues) 
  tickvaluehalign=center);
  barchart category=aedecod response=_1/ orient=horizontal datatransparency=1;
  endlayout;
**  定義右側(cè)  **;
  layout overlay / walldisplay=none xaxisopts=(tickvalueattrs=(size=7) display=(line tickvalues)
  griddisplay=on linearopts=(viewmin=0 viewmax=70 tickvaluesequence=(start=0 end=70 increment=10)))
  yaxisopts=(display=none reverse=true);
  barchart category=aedecod response=_2/
  group=MYID_GRD orient=horizontal dataskin=pressed segmentlabel=true
  segmentlabelattrs=(color=white);
  entry "Treatment 2 (N=&n2.)" / autoalign=(bottomright);
  endlayout;
**  定義底部屬性,sidebar可以用來放置附加信息,比如圖例相關(guān)信息  **;
  sidebar / align=bottom;
  discretelegend "bar1" / across=1 halign=center title="Patients (%)"
  itemsize=(fillheight=10px fillaspectratio=golden) border=false;
  endsidebar;
  endlayout;
  endgraph;
  end;
run;
**  輸出文件  **;
ods listing gpath="pathname";
ods graphics on/ reset imagename="f_butterfly" outputfmt=png width=1100px height=700px noborder;

proc sgrender data=fin template=fly;
run;

ods html close;
ods listing;
**  dummy data  **;
data adae; 
infile datalines delimiter = ','; 
input usubjid :$18. trta $ trtan aedecod :$200. aetoxgrn ; 
datalines; 
PHARM-ABC-100-0005, TRT A, 1, Bloating, 1 
PHARM-ABC-100-0005, TRT A, 1, Chills, 1 
PHARM-ABC-100-0005, TRT A, 1, Myalgia, 1 
PHARM-ABC-100-0005, TRT A, 1, Sinus tachycardia, 2 
PHARM-ABC-100-0005, TRT A, 1, Nausea, 3 
PHARM-ABC-101-0005, TRT A, 1, Hypotension, 3 
PHARM-ABC-101-0004, TRT A, 1, Bloating, 1 
PHARM-ABC-101-0004, TRT A, 1, Chills, 2 
PHARM-ABC-101-0004, TRT A, 1, Blood lactic acid increased, 1 
PHARM-ABC-101-0004, TRT A, 1, Diarrhoea, 1 
PHARM-ABC-101-0004, TRT A, 1, Hypoglycaemia, 1 
PHARM-ABC-101-0004, TRT A, 1, Hypomagnesaemia, 1 
PHARM-ABC-101-0004, TRT A, 1, Hypotension, 2 
PHARM-ABC-101-0004, TRT A, 1, Hypoxia, 2 
PHARM-ABC-101-0004, TRT A, 1, Nausea, 1 
PHARM-ABC-101-0004, TRT A, 1, Pollakiuria, 1 
PHARM-ABC-101-0004, TRT A, 1, Skin infection, 2 
PHARM-ABC-101-0004, TRT A, 1, Thrombocytopenia, 2 
PHARM-ABC-101-0005, TRT A, 1, Arthralgia, 1 
PHARM-ABC-101-0005, TRT A, 1, Back pain, 1 
PHARM-ABC-101-0005, TRT A, 1, Bloating, 1 
PHARM-ABC-101-0005, TRT A, 1, Cough, 1 
PHARM-ABC-101-0005, TRT A, 1, Dyspnoea exertional, 1 
PHARM-ABC-101-0005, TRT A, 1, Fatigue, 1 
PHARM-ABC-101-0005, TRT A, 1, Nausea, 1 
PHARM-ABC-101-0005, TRT A, 1, Oropharyngeal pain, 1 
PHARM-ABC-101-0005, TRT A, 1, Tachycardia, 1 
PHARM-ABC-101-0006, TRT A, 1, Bloating, 2 
PHARM-ABC-101-0006, TRT A, 1, Hypotension, 2 
PHARM-ABC-101-0006, TRT B, 2, Hypoxia, 2 
PHARM-ABC-101-0006, TRT B, 2, Nausea, 1 
PHARM-ABC-101-0006, TRT B, 2, Pleural effusion, 2 
PHARM-ABC-101-0006, TRT B, 2, Tachycardia, 2 
PHARM-ABC-101-0006, TRT B, 2, Thrombocytopenia, 1 
PHARM-ABC-102-0004, TRT B, 2, Abdominal pain upper, 3 
PHARM-ABC-102-0004, TRT B, 2, Cough, 1 
PHARM-ABC-102-0004, TRT B, 2, Hypoxia, 1 
PHARM-ABC-102-0004, TRT B, 2, Nausea, 1 
PHARM-ABC-102-0004, TRT B, 2, Pulmonary embolism, 2 
PHARM-ABC-102-0004, TRT B, 2, Skin laceration, 1 
PHARM-ABC-102-0005, TRT B, 2, Abdominal discomfort, 1 
PHARM-ABC-102-0005, TRT B, 2, Adrenal insufficiency, 2 
PHARM-ABC-102-0005, TRT B, 2, Arthralgia, 2 
PHARM-ABC-102-0005, TRT B, 2, Bloating, 1
PHARM-ABC-102-0005, TRT B, 2, Chest discomfort, 1 
PHARM-ABC-102-0005, TRT B, 2, Chills, 2 
PHARM-ABC-102-0005, TRT B, 2, Decreased appetite, 1 
PHARM-ABC-102-0005, TRT B, 2, Fatigue, 2 
PHARM-ABC-102-0005, TRT B, 2, Hepatitis, 1 
PHARM-ABC-102-0005, TRT B, 2, Hypoxia, 1 
PHARM-ABC-102-0005, TRT B, 2, Myalgia, 1 
PHARM-ABC-102-0005, TRT B, 2, Pain in extremity, 1 
PHARM-ABC-102-0005, TRT B, 2, Skin mass, 1
;
run; 

** Add Total Treatment group **;
data adae1; 
    set adae;
    output; 
    trtan = 99;
    trta = 'Total'; 
    output; 
run; 

** Count Bign **;
proc sql noprint;
select count(distinct usubjid) into :n1 trimmed from adae1 where trtan=1;
select count(distinct usubjid) into :n2 trimmed from adae1 where trtan=2;
select count(distinct usubjid) into :n3 trimmed from adae1 where trtan=99;
quit;

proc sort data = adae1(where=(aedecod ne "")); 
by trtan usubjid aedecod descending aetoxgrn; 
run; 
data ae_max; 
set adae1; 
by trtan usubjid aedecod descending aetoxgrn; 
if first.aedecod; 
run; 

proc freq data=ae_max noprint;
table aedecod*trtan*aetoxgrn/out=freq1(drop=percent);
run;

proc freq data=ae_max noprint;
table aedecod*trtan/out=freq2(drop=percent);
run;

proc transpose data=freq2 out=freq3 prefix=_;
by aedecod;
id trtan;
var count;
run;

data temp1;
    set freq1;
    if trtan=1 then perc=input(put((count / &n1)*100,5.),8.);
    if trtan=2 then perc=input(put((count / &n2)*100,5.),8.);
    if trtan=99 then perc=input(put((count / &n3)*100,5.),8.);
run;

proc sort data=temp1;
by aedecod aetoxgrn trtan;
run;

proc transpose data = temp1 out = temp2 (drop = _name_) prefix=_; 
    by aedecod aetoxgrn; 
    id trtan; 
    var perc; 
run; 

data temp2;
    set temp2;
    if _1=. then _1=0;
    if _2=. then _2=0;
proc sort;
by aedecod;
run;

data temp3;
    set freq3;
    perc99=input(put((_99 / &n3)*100,5.),8.);
    keep aedecod perc99;
proc sort;
by aedecod;
run;

data fin;
    merge temp2 temp3;
    by aedecod;
    if perc99>=10;
    grade="Grade "||strip(put(aetoxgrn,8.));
    tox=put(aetoxgrn,best.);
/*  _1=-_1;*/
    label
    aedecod = "Preferred Term"
    _1= "Percent Subjects Trt A"
    _2= "Percent Subjects Trt B"
    perc99= "Percent Subjects Total";
proc sort;
by descending perc99;
run;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容