/***********************************************************************************
* Program/Macro: Figure 9 Lab Shift Plots
* Lang/Vers: SAS V9.2
* Author: Susan Schwartz - SAS institute
* Date: 1/12/2012
* Description:
* This code was inspired from original code created by Susan Schwartz at the SAS
* institute. Code from her 2009 paper Schwartz, Susan. 2009 “Clinical Trial Reporting
* Using SAS/GRAPH® SG Procedures.” Proceedings of the SAS Global Forum 2009 Conference.
* Cary, NC: SAS Institute Inc. Available at
*
* The original code from the paper was only the last sgpanel code, the other code (creating
* data etc. came from the online site
* Edit Log: 12Jan2012 first version complete
***********************************************************************************/
/* The below code pulls in the ADLBC dataset from the CTSPedia site and selects
* the appropriate lab tests. Specific visits are chosen and the upper limit of
* normal value (xuln) is calculated. Treatments are named and the data is subset
* by baseline value and post baseline value. The new datasets are merged and
* the resulting dataset is graphed using the same code as above to produce similar
* output which is relavent to the CTSPedia dataset. */
/* Create template for the graphic. Code taken direcly from the above reference */
proctemplate;
definestyle listingSmallFont;
parent = styles.listing;
style GraphFonts from GraphFonts
"Fonts used in graph styles" /
'GraphUnicodeFont' = ("",9pt)
'GraphValueFont' = (", ",8pt)
'GraphLabelFont' = (", ",9pt)
'GraphFootnoteFont' = (", ",8pt)
'GraphTitleFont' = (", ",11pt,bold);
end;
run;
PROCIMPORTOUT= WORK.adlbc
DATAFILE= “Location\ADLBC.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
/* Create macro so that only entry of the 2 specific lab test names is needed */
%macro shiftplot (labtest1=, labtest2=);
/* Pull out specific lab tests and visits from the ADLBC dataset */
data labs;
set adlbc;
if lbtest in ("&labtest1", "&labtest2");
keep usubjid lbtest lbstresn lbstnrhi xuln trtpn treat visit visitnum;
xuln = lbstresn/lbstnrhi;
if trtpn=0 then treat='Placebo';
else treat='Active';
run;
/* Create macro variable for maximum xULN so that axes make sense. Also create
macro variables for 2 reference lines that will be evenly distributed on the
plot based upon the maximum uln value. Added 1 to uln max value so that the
actual maximum value was not plotted on the edge of the axis.*/
proc means data=labs noprint;
var xuln;
output out=maxuln max=xulnmax;
run;
data maxuln;
set maxuln;
format xulnmax 2. ref1 2. ref2 2.;
xulnmax=xulnmax+1;
ref1=xulnmax/3;
ref2=2*ref1;
run;
data maxuln;
set maxuln;
call symput('maxuln',xulnmax);
call symput('ref1', ref1);
call symput('ref2', ref2);
run;
ods listing;
proc print;
title "Maximum value for axis is &maxuln";
run;
ods listing close;
/* Sort and subset the data to create a baseline dataset and a postbaseline
dataset. Merge the two so that the data is ready for graphing */
proc sort data=labs;
by usubjid lbtest visitnum;
run;
data base;
set labs;
keep usubjid lbtest baseval;
if visitnum=1;
baseval=xuln;
run;
data post;
set labs;
keep usubjid lbtest visitnum xuln treat visit studyval;
if visitnum>1;
studyval=xuln;
run;
data labshift;
merge post base;
by usubjid lbtest;
if xuln ne .;
if treat='Placebo' then xref=0;
else xref=100;
if treat='Placebo' then yref=0;
else yref=100;
run;
proc sort data=labshift;
by visitnum;
run;
/* Sort dataset appropriately for the graphing function */
proc sort data=labshift;
by usubjid lbtest;
run;
/* Prepare the output (html) location and create the graphic, panel by labtest and
graph baseline (x-axis) versus post-baseline (y-axis) by visit */
goptions reset=all;
ods listing close;
ods html file='safety.html' path='.' style=listingSmallFont;
ods graphics on / reset imagefmt=gif width=650px height=494px
imagename='ClinicalHandout_SafetyPanel';
title 'Laboratory Shift Plots, Baseline vs. On-study';
title2 ' ';
footnote1 ' ';
footnote2 j=l '*ULN - Upper Limit of Normal';
footnote3 j=l 'Add specific information or explanation of concern levels for parameters here';
proc sgpanel data=labshift;
panelby lbtest/ layout=columnlattice onepanel novarname;
scatter x=baseval y=studyval / group=treat markerattrs=(size=9);
series x=xref y=yref / legendlabel="Reference line" markerattrs=(size=0) lineattrs=(thickness=0.2 pattern=dash);
refline &ref1 &ref2/ axis=Y lineattrs=(pattern=dash);
refline &ref1 &ref2 / axis=X lineattrs=(pattern=dash);
rowaxis integer min=0 max=&maxuln label='Study (/ULN)';
colaxis integer min=0 max=&maxuln label='Baseline (/ULN) *';
keylegend / title=" " noborder;
run;
ods html close;
%mend shiftplot;
/* Run macro with specific lab tests */
%shiftplot(labtest1=ALBUMIN, labtest2=CREATINE KINASE);