"Now the client requires separate output based on every param " Can you post a picture to explain what you want to do ? If it is just a BAR graph ,that is very easy . Here is an example: libname x v9 'c:\temp'; proc sgpanel data=x.adqs4_01; panelby PARAML/layout=columnlattice onepanel novarname; hbar VISLBL/group=TYPEAE ; run;
Thank you for the response, I had tweaked the code using the trtpn variable but not able to figure out where to resolve the issue with highlow values that is where i got stuck, i had given separate condition for both trt groups for high low values and its not working, is there any idea that you can give me here, the below is the modified code.
proc format;
picture fmt
low-<0='000%' (mult=100)
0-high='000%' (mult=100)
;
value fmt_freq
1='Rarely'
2='Occasionaly'
3='Frequently'
4='Almost Constantly'
;
value $grade
'Severity'=1
'Frequency'=2
'Interference'=3
'Presence/Absence'=4
;
run;
proc sql;
create table ADQS4 as
select USUBJID,PARAM, PARAML,TYPEAE,VISLBL,TRTPN,AVALC,AVALUPDT, strip(put(AVALUPDT,8.)) as AVAL_c,
input(scan(PARAML,-1,'() '),best.) as freq from ANA.ADQS4
where pepfl="Y" and RANDFL='Y' /*and PARAML='Vomiting (10)'*/
AND TYPEAE NE 'Composite' AND AVISITN NOT IN(1301,1401) /*AND USUBJID EQ '1280-0022-1036002001'*/;
quit;
data ADQS4_01;
set ADQS4;
if TYPEAE ='Severity' then type=1;
if TYPEAE ='Frequency' then type=2;
if TYPEAE ='Interference' then type=3;
if TYPEAE ='Presence/Absence' then type=4;
if freq=2 and TYPEAE ='Severity' then figno='01.01';
if freq=4 and TYPEAE ='Severity' then figno='01.02';
if freq=8 and TYPEAE ='Severity' then figno='01.03';
if freq=8 and TYPEAE ='Interference' then figno='01.04';
if freq=10 and TYPEAE ='Severity' then figno='01.05';
if freq=10 and TYPEAE ='Frequency' then figno='01.06';
if freq=11 and TYPEAE ='Severity' then figno='01.07';
if freq=11 and TYPEAE ='Frequency' then figno='01.08';
if freq=16 and TYPEAE ='Frequency' then figno='01.09';
if freq=17 and TYPEAE ='Severity' then figno='01.10';
if freq=17 and TYPEAE ='Frequency' then figno='01.11';
if freq=17 and TYPEAE ='Interference' then figno='01.12';
if freq=23 and TYPEAE ='Presence/Absence' then figno='01.13';
if vislbl='Baseline' then visit=-0.5;
if vislbl='Cycle 2' then visit=1;
if vislbl='Cycle 3' then visit=2;
if vislbl='Cycle 4' then visit=3;
if vislbl='Cycle 5' then visit=4;
if vislbl='Cycle 6' then visit=5;
if vislbl='Cycle 7' then visit=6;
if vislbl='Cycle 8' then visit=7;
if vislbl='Cycle 9' then visit=8;
if vislbl='Cycle 10' then visit=9;
if vislbl='Cycle 11' then visit=10;
if vislbl='Cycle 12' then visit=11;
if vislbl='Cycle 13' then visit=12;
if vislbl='Cycle 14' then visit=13;
if vislbl='Cycle 15' then visit=14;
if vislbl='Cycle 16' then visit=15;
if AVALC='NONE' then aval_cal=0;
if AVALC='NEVER' then aval_cal=0;
if AVALC='NOT AT ALL' then aval_cal=0;
if AVALC='MILD' then aval_cal=1;
if AVALC='MODERTATE' then aval_cal=2;
if AVALC='SEVERE' then aval_cal=3;
if AVALC='VERY SEVERE' then aval_cal=4;
if AVALC='QUITE A BIT' then aval_cal=5;
if AVALC='A LITTLE BIT' then aval_cal=6;
if AVALC='SOMEWHAT' then aval_cal=7;
if AVALC='RARELY' then aval_cal=8;
if AVALC='OCCASIONALLY' then aval_cal=9;
if AVALC='FREQUENTLY' then aval_cal=10;
if AVALC='ALMOST CONSTANTLY' then aval_cal=11;
if AVALC='VERY MUCH' then aval_cal=12;
run;
data ADQS4_1;
set ADQS4_01;
where figno='01.01';
run;
proc sort data=ADQS4_1;by visit freq trtpn;run;
data ADQS4_1;
set ADQS4_1;
by visit freq trtpn;
left=first.trtpn ;
run;
proc sql;
create table ADQS4_2 as
select visit,left,freq,TRTPN,aval_cal,
count(*)/(select count(*) from ADQS4_1 where visit=a.visit) as pct
from ADQS4_1 as a
group by visit,left,freq,trtpn,aval_cal;
quit;
/*calculating count and percent for the total findings by visit and percentage for no vomitings*/
proc sql;
create table ADQS4_trtN as
select visit,left,freq,TRTPN,count(*) as n,aval_cal
from ADQS4_1 as a
group by visit,trtpn;
create table ADQS4_trt1N as
select distinct visit,trtpn,n from ADQS4_trtN;
quit;
proc sort data=ADQS4_trt1N;
by visit;
run;
proc transpose data=ADQS4_trt1N out=ADQS4_trt1N_t(drop=_name_ rename=(_1=n1 _2=n2));
by visit;
var TRTPN n;
id TRTPN;
run;
data ADQS4_count;
set ADQS4_trt1N_t;
if _LABEL_ ='Planned Treatment (N)' then delete;
drop _LABEL_;
run;
proc sql;
create table ADQS4_trtNP as
select visit,left,freq,TRTPN,count(*) as np,aval_cal
from ADQS4_1 as a
group by visit,trtpn,aval_c
having aval_cal=0;
create table ADQS4_trtNP1 as
select distinct visit,trtpn,np from ADQS4_trtNP;
quit;
proc sort data=ADQS4_trtNP1;
by visit;
run;
proc transpose data=ADQS4_trtNP1 out=ADQS4_trtNP1_t(drop=_name_ rename=(_1=pn1 _2=pn2));
by visit;
var TRTPN np;
id TRTPN;
run;
/*counting the percentage of not at all category per visit*/
data ADQS4_count_per;
set ADQS4_trtNP1_t;
if _LABEL_ ='Planned Treatment (N)' then delete;
drop _LABEL_;
rename visit=visit1;
run;
/*joining the count and percent*/
proc sql;
create table cnt_pct as
select a.pn1,a.pn2,b.* from ADQS4_count_per as a join ADQS4_count as b on
a.visit1=b.visit;
quit;
***************************************************************************;
proc sort data=ADQS4_2 out=ADQS4_2_nsort;
by visit trtpn;
run;
data ADQS4_3;
set /*ADQS4_2*/ ADQS4_2_nsort;
by visit trtpn;
if first.trtpn then cum=0;
cum+pct;
run;
data ADQS4_4;
set ADQS4_3;
if trtpn then cum=-cum;
run;
proc sort data=ADQS4_4;
by visit trtpn aval_cal;
run;
data ADQS4_5;
set ADQS4_4;
by visit trtpn aval_cal;
lag_cum=lag(cum);
if first.trtpn then lag_cum=0;
drop pct;
run;
data ADQS4_6;
set ADQS4_5;
if trtpn=1 then do;high=lag_cum;low=cum;end;
else do;high=cum;low=lag_cum;end;
if trtpn=2 then do; high=cum; low=lag_cum;end;
else do;high=lag_cum;low=cum;end;
drop cum lag_cum;
run;
/*merging the count and main dataset*/
proc sort data=ADQS4_6 out=ADQS4_6_s;
by visit;
run;
proc sort data=cnt_pct out=cnt_pct_s;
by visit;
run;
data pre_final;
merge ADQS4_6_s cnt_pct_s;
by visit;
run;
data final_g_(drop=pn1 pn2 n1_ n2_);
set /*ADQS4_6*/ pre_final(rename=(n1=n1_ n2=n2_));
by visit;
if first.visit then do;
n_one=-1.1;
n_zero=-0.1;
p_zero=0.1;
p_one=1.1;
p1_p=-0.9;
p2_p=0.9;
zero=0;
n1=n1_;
n2=n2_;
p1=cat(put((pn1/n1)*100,8.),'%');
p2=cat(put((pn2/n1)*100,8.),'%');
select(visit);
when(-0.5) text='Baseline';
when(1) text='Cycle 2';
when(2) text='Cycle 3';
when(3) text='Cycle 4';
when(4) text='Cycle 5';
when(5) text='Cycle 6';
when(6) text='Cycle 7';
when(7) text='Cycle 8';
when(8) text='Cycle 9';
when(9) text='Cycle 10';
when(10) text='Cycle 11';
when(11) text='Cycle 12';
when(12) text='Cycle 13';
when(13) text='Cycle 14';
otherwise;
end;
end;
/*figno=&figno.;*/
if high<=0 then do;high=high-0.1;low=low-0.1;end;
if low>=0 then do;high=high+0.1;low=low+0.1;end;
run;
/*proc sort data=final_g_;*/
/*by visit;*/
/*run;*/
proc format;
value fmt_freq
2='Rarely'
4='Occasion'
8='Frequent'
10='Almost Constantly'
11='Almost 1'
16='Almost 2'
17='Almost 3'
23='Almost 4'
;
run;
proc format;
value fmt_fre
.='Missing'
0='None'
1='Mild'
2='Moderate'
3='Severe'
4='Rarely'
5='Occassion'
;
run;
data final_g;
set final_g_;
format aval_cal fmt_fre. low high fmt. ;
figno='01.01';
run;
/*generaing graph*/
options leftmargin = 1.5cm rightmargin = 1.5cm topmargin = 1.5cm bottommargin = 2.0cm
formchar = '|----|+|---+=|-/<>*' nonumber nodate nocenter nomprint
orientation=landscape papersize=A4 dev=PNG300;
/*goptions XPIXELS=0 YPIXELS=0;*/
ods graphics on / reset = all width = 25.6cm height = 15.4cm noborder;
ods pdf file = "&outpath\BI9009A_F01_PRO_CTCAE_Stacked_BAR_Chart_v1_0.pdf"
pdftoc=1 compress=9 uniform nopdfnote nogtitle nogfootnote dpi=300 ;
proc sgplot data=final_g noborder;
Where figNo = "01.01";
title 'Xenutuzumab with E+E Placebo with E+E ';
styleattrs datacolors=( yellow orange navy verylightblue green pink) ;
highlow y=visit low=n_one high=n_zero/type=bar fillattrs=(color=verydarkgreen)
nooutline transparency=0.8 name='n' legendlabel='Never';
highlow y=visit low=p_zero high=p_one/type=bar fillattrs=(color=verydarkgreen)
nooutline transparency=0.8;
highlow y=visit low=low high=high/type=bar group=aval_cal nooutline name='a';
scatter y=visit x=p1_p/markerchar=p1 markercharattrs=(size=8) x2axis;
scatter y=visit x=p2_p/markerchar=p2 markercharattrs=(size=8) x2axis;
text y=visit x=zero text=text/strip contributeoffsets=none splitchar=' ' splitpolicy=splitalways textattrs=(size=8);
yaxistable n1/y=visit location=outside position=left valueattrs=(size=8 ) VALUEJUSTIFY=right VALUEHALIGN=right ;
yaxistable n2/y=visit location=outside position=right valueattrs=(size=8) VALUEJUSTIFY=left VALUEHALIGN=left;
xaxis values=(-1.1 to 1.1 by 0.2) display=(nolabel noline) valuesdisplay=(
'100%' '80%' '60%' '40%' '20%' '0%' '0%' '20%' '40%' '60%' '80%' '100%') offsetmin=0 offsetmax=0 ;
x2axis values=(-1 -0.7 0 0.7 1) display=(nolabel noline noticks) valuesdisplay=(
' ' 'Patients Without Symp(%)' ' ' 'Patients Without Symp(%)' ' ') offsetmin=0 offsetmax=0 ;
yaxis reverse display=none ;
keylegend 'n' 'a' /title='Frequency:';
ods pdf close;
thanks for your time and help.
yes, they are two trt arms
two trt arms must come on left and right side with aval values should be differentiated in each visit with different colours based on their percentage and this way we are trying to generate 13 graphs for 13 different paraml.
/**************************
I noticed that there is a variable named "Planned Treatment (N)" in table ADQS4.
So I assume it is the treatment variable, but there is only one value "2" in table ADQS4.
Therefor, I make a DUMMY data to include treatment=1 data .Check the following how to make treatment=1 data.
***************************/
libname ana v9 'c:\temp';
data temp1; /*<---Notice: I make a DUMMY dataset for treatment=1*/
set ANA.ADQS4;
TRTPN=1;
keep TYPEAE VISLBL TRTPN;
run;
data temp2;
set ANA.ADQS4;
keep TYPEAE VISLBL TRTPN;
run;
data have;
set temp1 temp2;
run;
data have;
set have;
if TYPEAE ='Severity' then type=4;
if TYPEAE ='Frequency' then type=3;
if TYPEAE ='Interference' then type=2;
if TYPEAE ='Presence/Absence' then type=1;
if vislbl='Baseline' then visit=-0.5;
if vislbl='Cycle 2' then visit=1;
if vislbl='Cycle 3' then visit=2;
if vislbl='Cycle 4' then visit=3;
if vislbl='Cycle 5' then visit=4;
if vislbl='Cycle 6' then visit=5;
if vislbl='Cycle 7' then visit=6;
if vislbl='Cycle 8' then visit=7;
if vislbl='Cycle 9' then visit=8;
if vislbl='Cycle 10' then visit=9;
if vislbl='Cycle 11' then visit=10;
if vislbl='Cycle 12' then visit=11;
if vislbl='Cycle 13' then visit=12;
if vislbl='Cycle 14' then visit=13;
if vislbl='Cycle 15' then visit=14;
if vislbl='Cycle 16' then visit=15;
run;
proc sql;
create table have2 as
select TRTPN,visit,type,
count(*)/(select count(*) from have where TRTPN=a.TRTPN and visit=a.visit) as pct
from have as a
group by TRTPN,visit,type ;
quit;
data have3;
set have2;
by TRTPN visit ;
if first.visit then cum=0;
cum+pct;
run;
data have4;
set have3;
if TRTPN=1 then cum=-cum;
run;
data have5;
set have4;
by TRTPN visit;
lag_cum=lag(cum);
if first.visit then lag_cum=0;
drop pct;
run;
data have6;
set have5;
if TRTPN=1 then do;high=lag_cum;low=cum;end;
else do;high=cum;low=lag_cum;end;
drop cum lag_cum;
run;
proc format;
value visit
-0.5='Baseline'
1='Cycle 1'
2='Cycle 2'
3='Cycle 3'
4='Cycle 4'
5='Cycle 5'
6='Cycle 6'
7='Cycle 7'
8='Cycle 8'
9='Cycle 9'
10='Cycle 10'
11='Cycle 11'
12='Cycle 12'
13='Cycle 13'
14='Cycle 14'
15='Cycle 15'
16='Cycle 16'
;
value type(notsorted)
1='Presence/Absence'
2='Interference'
3='Frequency'
4='Severity'
;
run;
data have7;
set have6;
by TRTPN visit;
if TRTPN=1 and first.visit then do;
/*
n_one=-1.1;
n_zero=-0.1;
p_zero=0.1;
p_one=1.1;
p1_p=-0.9;
p2_p=0.9;
*/
zero=0;
text=put(visit,visit. -l);
end;
format visit visit. type type. ;
if high<=0 then do;high=high-0.1;low=low-0.1;end;
if low>=0 then do;high=high+0.1;low=low+0.1;end;
run;
proc sgplot data=have7 noborder;
title 'Tagrisson 80 mg Chemotherapy ';
styleattrs datacolors=(navy orange yellow lightgreen) ;
/*
highlow y=visit low=n_one high=n_zero/type=bar fillattrs=(color=verydarkgreen)
nooutline transparency=0.8 name='n' legendlabel='Never';
highlow y=visit low=p_zero high=p_one/type=bar fillattrs=(color=verydarkgreen)
nooutline transparency=0.8;
*/
highlow y=visit low=low high=high/type=bar group=type nooutline name='a';
/*scatter y=visit x=p1_p/markerchar=p1 markercharattrs=(size=8) x2axis;*/
/*scatter y=visit x=p2_p/markerchar=p2 markercharattrs=(size=8) x2axis;*/
text y=visit x=zero text=text/strip contributeoffsets=none /*splitchar=' ' splitpolicy=splitalways*/ textattrs=(size=8);
/*yaxistable n1/y=visit location=outside position=left valueattrs=(size=8 ) VALUEJUSTIFY=right VALUEHALIGN=right ;*/
/*yaxistable n2/y=visit location=outside position=right valueattrs=(size=8) VALUEJUSTIFY=left VALUEHALIGN=left;*/
xaxis values=(-1.1 to 1.1 by 0.2) display=(nolabel noline) valuesdisplay=(
'100%' '80%' '60%' '40%' '20%' '0%' '0%' '20%' '40%' '60%' '80%' '100%') offsetmin=0 offsetmax=0 ;
x2axis values=(-1 -0.7 0 0.7 1) display=(nolabel noline noticks) valuesdisplay=(
' ' 'Patients Without Symp(%)' ' ' 'Patients Without Symp(%)' ' ') offsetmin=0 offsetmax=0 ;
yaxis reverse display=none ;
keylegend /*'n'*/ 'a' /title='Frequency:' ;
run;
we were having a trtpn variable with both treatments 1 and 2, i think we don't need a dummy variable for trt 1 and within the program which i had tweaked i had written a condition and created a type variable and that is the type of condition we are looking for for each graph, there are 13 different type of conditions that we have got for 13 different graphs. In the output as well we would need colour code for mild moderate, severe, very severe and none which we can find that in avalc variable, i think the graph that was derived with colour code differentiation was done for TYPEAE, but this TYPEAE variable is having interference, severity and frequency which should go individullay with every paraml and create a individual graph for every paraml and typeae. hope i am not confusing.
sure thank you, i will make changes accordingly and will let you know if i need any help and will also post the final code if i am successful in getting the output i need. For your reference i had copied the whole dataset. I will try from my end and will update you.
Here is for NON-Missing value.
/**************************
OK.Here is for your 13 Graphics.
Use "AVALC" to calculated percent instead of "TYPEAE".
***************************/
libname ana v9 'c:\temp';
proc format;
value visit
-0.5='Baseline'
1='Cycle 1'
2='Cycle 2'
3='Cycle 3'
4='Cycle 4'
5='Cycle 5'
6='Cycle 6'
7='Cycle 7'
8='Cycle 8'
9='Cycle 9'
10='Cycle 10'
11='Cycle 11'
12='Cycle 12'
13='Cycle 13'
14='Cycle 14'
15='Cycle 15'
16='Cycle 16'
;
value avalc
/*.='Missing'*/
12='NEVER'
11='MILD'
10='MODERTATE'
9='SEVERE'
8='VERY SEVERE'
7='QUITE A BIT'
6='A LITTLE BIT'
5='SOMEWHAT'
4='RARELY'
3='OCCASIONALLY'
2='FREQUENTLY'
1='ALMOST CONSTANTLY'
0='VERY MUCH'
;
run;
%macro plotit(dsn=,PARAML=,TYPEAE=);
data have;
set &dsn.;
if PARAML="&PARAML." and TYPEAE="&TYPEAE.";
keep AVALC VISLBL TRTPN;
run;
data have;
set have;
if AVALC='NONE' then aval_cal=12;
if AVALC='NEVER' then aval_cal=12;
if AVALC='NOT AT ALL' then aval_cal=12;
if AVALC='MILD' then aval_cal=11;
if AVALC='MODERTATE' then aval_cal=10;
if AVALC='SEVERE' then aval_cal=9;
if AVALC='VERY SEVERE' then aval_cal=8;
if AVALC='QUITE A BIT' then aval_cal=7;
if AVALC='A LITTLE BIT' then aval_cal=6;
if AVALC='SOMEWHAT' then aval_cal=5;
if AVALC='RARELY' then aval_cal=4;
if AVALC='OCCASIONALLY' then aval_cal=3;
if AVALC='FREQUENTLY' then aval_cal=2;
if AVALC='ALMOST CONSTANTLY' then aval_cal=1;
if AVALC='VERY MUCH' then aval_cal=0;
if vislbl='Baseline' then visit=-0.5;
if vislbl='Cycle 2' then visit=1;
if vislbl='Cycle 3' then visit=2;
if vislbl='Cycle 4' then visit=3;
if vislbl='Cycle 5' then visit=4;
if vislbl='Cycle 6' then visit=5;
if vislbl='Cycle 7' then visit=6;
if vislbl='Cycle 8' then visit=7;
if vislbl='Cycle 9' then visit=8;
if vislbl='Cycle 10' then visit=9;
if vislbl='Cycle 11' then visit=10;
if vislbl='Cycle 12' then visit=11;
if vislbl='Cycle 13' then visit=12;
if vislbl='Cycle 14' then visit=13;
if vislbl='Cycle 15' then visit=14;
if vislbl='Cycle 16' then visit=15;
run;
proc sql;
create table have2 as
select TRTPN,visit,aval_cal,
count(*)/(select count(*) from have where TRTPN=a.TRTPN and visit=a.visit and aval_cal is not missing) as pct /* aval_cal is not missing*/
from have as a
where aval_cal is not missing /* aval_cal is not missing*/
group by TRTPN,visit,aval_cal ;
quit;
data have3;
set have2;
by TRTPN visit ;
if first.visit then cum=0;
cum+pct;
run;
data have4;
set have3;
if TRTPN=1 then cum=-cum; /*left side data*/
run;
data have5;
set have4;
by TRTPN visit;
lag_cum=lag(cum);
if first.visit then lag_cum=0;
drop pct;
run;
data have6;
set have5;
if TRTPN=1 then do;high=lag_cum;low=cum;end;
else do;high=cum;low=lag_cum;end;
drop cum lag_cum;
run;
data have7;
set have6;
by TRTPN visit;
if TRTPN=1 and first.visit then do;
zero=0;
text=put(visit,visit. -l);
end;
format visit visit. aval_cal avalc. ;
if high<=0 then do;high=high-0.1;low=low-0.1;end;
if low>=0 then do;high=high+0.1;low=low+0.1;end;
run;
proc sort data=have7;by TRTPN visit descending aval_cal;run;
proc sgplot data=have7 noborder;
title "PARAML=&PARAML. TYPEAE=&TYPEAE. ";
title2 'Tagrisson 80 mg Chemotherapy ';
styleattrs datacolors=( verylightgreen navy blue yellow orange lightblue green lightred red) ;
highlow y=visit low=low high=high/type=bar group=aval_cal grouporder=data nooutline name='a';
text y=visit x=zero text=text/strip contributeoffsets=none /*splitchar=' ' splitpolicy=splitalways*/ textattrs=(size=8);
xaxis values=(-1.1 to 1.1 by 0.2) display=(nolabel noline) valuesdisplay=(
'100%' '80%' '60%' '40%' '20%' '0%' '0%' '20%' '40%' '60%' '80%' '100%') offsetmin=0 offsetmax=0 ;
x2axis values=(-1 -0.7 0 0.7 1) display=(nolabel noline noticks) valuesdisplay=(
' ' 'Patients Without Symp(%)' ' ' 'Patients Without Symp(%)' ' ') offsetmin=0 offsetmax=0 ;
yaxis reverse display=none ;
keylegend /*'n'*/ 'a' /title='Frequency:' ;
run;
%mend;
proc freq data=ANA.ADQS4 noprint;
table PARAML*TYPEAE/out=levels list;
run;
data _null_;
set levels;
call execute( catt('%plotit(dsn=ANA.ADQS4,PARAML=',PARAML,',TYPEAE=',TYPEAE,')') );
run;
Here is for Missing value.
/**************************
OK.Here is for your 13 Graphics.
Use "AVALC" to calculated percent instead of "TYPEAE".
***************************/
libname ana v9 'c:\temp';
proc format;
value visit
-0.5='Baseline'
1='Cycle 1'
2='Cycle 2'
3='Cycle 3'
4='Cycle 4'
5='Cycle 5'
6='Cycle 6'
7='Cycle 7'
8='Cycle 8'
9='Cycle 9'
10='Cycle 10'
11='Cycle 11'
12='Cycle 12'
13='Cycle 13'
14='Cycle 14'
15='Cycle 15'
16='Cycle 16'
;
value avalc
.='Missing'
12='NEVER'
11='MILD'
10='MODERTATE'
9='SEVERE'
8='VERY SEVERE'
7='QUITE A BIT'
6='A LITTLE BIT'
5='SOMEWHAT'
4='RARELY'
3='OCCASIONALLY'
2='FREQUENTLY'
1='ALMOST CONSTANTLY'
0='VERY MUCH'
;
run;
%macro plotit(dsn=,PARAML=,TYPEAE=);
data have;
set &dsn.;
if PARAML="&PARAML." and TYPEAE="&TYPEAE.";
keep AVALC VISLBL TRTPN;
run;
data have;
set have;
if AVALC='NONE' then aval_cal=12;
if AVALC='NEVER' then aval_cal=12;
if AVALC='NOT AT ALL' then aval_cal=12;
if AVALC='MILD' then aval_cal=11;
if AVALC='MODERTATE' then aval_cal=10;
if AVALC='SEVERE' then aval_cal=9;
if AVALC='VERY SEVERE' then aval_cal=8;
if AVALC='QUITE A BIT' then aval_cal=7;
if AVALC='A LITTLE BIT' then aval_cal=6;
if AVALC='SOMEWHAT' then aval_cal=5;
if AVALC='RARELY' then aval_cal=4;
if AVALC='OCCASIONALLY' then aval_cal=3;
if AVALC='FREQUENTLY' then aval_cal=2;
if AVALC='ALMOST CONSTANTLY' then aval_cal=1;
if AVALC='VERY MUCH' then aval_cal=0;
if vislbl='Baseline' then visit=-0.5;
if vislbl='Cycle 2' then visit=1;
if vislbl='Cycle 3' then visit=2;
if vislbl='Cycle 4' then visit=3;
if vislbl='Cycle 5' then visit=4;
if vislbl='Cycle 6' then visit=5;
if vislbl='Cycle 7' then visit=6;
if vislbl='Cycle 8' then visit=7;
if vislbl='Cycle 9' then visit=8;
if vislbl='Cycle 10' then visit=9;
if vislbl='Cycle 11' then visit=10;
if vislbl='Cycle 12' then visit=11;
if vislbl='Cycle 13' then visit=12;
if vislbl='Cycle 14' then visit=13;
if vislbl='Cycle 15' then visit=14;
if vislbl='Cycle 16' then visit=15;
run;
proc sql;
create table have2 as
select TRTPN,visit,aval_cal,
count(*)/(select count(*) from have where TRTPN=a.TRTPN and visit=a.visit ) as pct
from have as a
group by TRTPN,visit,aval_cal ;
quit;
data have3;
set have2;
by TRTPN visit ;
if first.visit then cum=0;
cum+pct;
run;
data have4;
set have3;
if TRTPN=1 then cum=-cum; /*left side data*/
run;
data have5;
set have4;
by TRTPN visit;
lag_cum=lag(cum);
if first.visit then lag_cum=0;
drop pct;
run;
data have6;
set have5;
if TRTPN=1 then do;high=lag_cum;low=cum;end;
else do;high=cum;low=lag_cum;end;
drop cum lag_cum;
run;
data have7;
set have6;
by TRTPN visit;
if TRTPN=1 and first.visit then do;
zero=0;
text=put(visit,visit. -l);
end;
format visit visit. aval_cal avalc. ;
if high<=0 then do;high=high-0.1;low=low-0.1;end;
if low>=0 then do;high=high+0.1;low=low+0.1;end;
run;
proc sort data=have7;by TRTPN visit descending aval_cal;run;
proc sgplot data=have7 noborder;
title "PARAML=&PARAML. TYPEAE=&TYPEAE. ";
title2 'Tagrisson 80 mg Chemotherapy ';
styleattrs datacolors=( verylightgreen navy blue yellow orange lightblue green lightred red) ;
highlow y=visit low=low high=high/type=bar group=aval_cal grouporder=data nooutline name='a';
text y=visit x=zero text=text/strip contributeoffsets=none /*splitchar=' ' splitpolicy=splitalways*/ textattrs=(size=8);
xaxis values=(-1.1 to 1.1 by 0.2) display=(nolabel noline) valuesdisplay=(
'100%' '80%' '60%' '40%' '20%' '0%' '0%' '20%' '40%' '60%' '80%' '100%') offsetmin=0 offsetmax=0 ;
x2axis values=(-1 -0.7 0 0.7 1) display=(nolabel noline noticks) valuesdisplay=(
' ' 'Patients Without Symp(%)' ' ' 'Patients Without Symp(%)' ' ') offsetmin=0 offsetmax=0 ;
yaxis reverse display=none ;
keylegend /*'n'*/ 'a' /title='Frequency:' ;
run;
%mend;
proc freq data=ANA.ADQS4 noprint;
table PARAML*TYPEAE/out=levels list;
run;
data _null_;
set levels;
call execute( catt('%plotit(dsn=ANA.ADQS4,PARAML=',PARAML,',TYPEAE=',TYPEAE,')') );
run;
this looks very good, thanks for providing this, i will let you know if i need any support. We are forwarding this to client next Tuesday and i am greatly thankful for your time and help and i had learned many new techniques. If you don't mind can you please help me understand the way you had calculated the high level values, the purpose of using lag function to calculate those values and you had calculated for left side values and how did it get split into two treatments and where is that option used to split the graph as a butterfly. If you can please provide me this, i can learn a new concept today. Thanks a million.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.