Hi All,
By using below code I am getting the following output.
SAS Code:
/*--Adverse Events timeline data--*/
data ae0;
retain aestdateMin;
retain aeendateMax;
attrib aestdate informat=yymmdd10. format=date7.;
attrib aeendate informat=yymmdd10. format=date7.;
format aestdateMin aeendateMax date7.;
drop aestdateMin aeendateMax;
input aeseq aedecod $ 5-39 aesev $ aestdate aeendate;
aestdateMin=min(aestdate, aestdateMin);
aeendateMax=max(aeendate, aeendateMax);
call symputx('mindate', aestdateMin);
call symputx('maxdate', aeendateMax);
y=aeseq;
if aedecod=" " then y=-9;
cards;
. MILD 2013-03-06 2013-03-06 Legend
. MODERATE 2013-03-06 2013-03-06 Legend
. SEVERE 2013-03-06 2013-03-06 Legend
1 DIZZINESS MODERATE 2013-03-06 2013-03-07
2 COUGH MILD 2013-03-20 .
3 APPLICATION SITE DERMATITIS MILD 2013-03-26 2013-06-18
4 DIZZINESS MILD 2013-03-27 2013-03-27
5 ELECTROCARDIOGRAM T WAVE INVERSION MILD 2013-03-30 .
6 DIZZINESS MILD 2013-04-01 2013-04-11
7 DIZZINESS MILD 2013-04-01 2013-11-11
8 APPLICATION SITE DERMATITIS MODERATE 2013-03-26 2013-06-18
9 HEADACHE MILD 2013-05-17 2013-05-18
10 APPLICATION SITE DERMATITIS MODERATE 2013-03-26 2013-06-18
11 PRURITUS MODERATE 2013-05-27 2013-06-18
;
run;
/*proc print;run;*/
/*--Evaluate min and max day and dates--*/
data _null_;
set ae0;
minday=0;
maxday= &maxdate - &mindate;
minday10 = -20;
mindate10=&mindate - 20;
call symputx('minday', minday);
call symputx('maxday', maxday);
call symputx('minday10', minday10);
run;
/*--Compute start and end date and bar caps based on event start, end--*/
data ae2;
set ae0;
aestdy= aestdate-&mindate+0;
aeendy= aeendate-&mindate+0;
stday=aestdy;
enday=aeendy;
if aestdy=. then do;
stday=&minday;
lcap='ARROW';
end;
if aeendy=. then do;
enday=&maxday;
hcap='ARROW';
end;
xs=0;
run;
/*ods escapechar="^";*/
/*--Custom style for severity of events--*/
proc template;
define Style AETimelineV93;
parent = styles.htmlblue;
style GraphColors from graphcolors /
"gdata1" = cx5fcf5f
"gdata2" = cxdfcf3f
"gdata3" = cxbf3f3f;
style GraphFonts from GraphFonts /
'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",5pt)
'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",7pt)
'GraphTitleFont' = ("<sans-serif>, <MTsans-serif>",11pt);
end;
run;
/*--Draw the Graph--*/
ods html close;
ods graphics / reset width=5in height=3in imagename="Fig12_6_AETimeline_V93";
ods listing style=AETimelineV93 image_dpi=100;
title "Adverse Events for Patient Id = xx-xxx-xxxx";
proc sgplot data=ae2 noautolegend nocycleattrs;
/*--Draw the events--*/
highlow y=aeseq low=stday high=enday / group=aesev lowlabel=aedecod type=bar
barwidth=0.8 lineattrs=(color=black) lowcap=lcap highcap=hcap name='sev';
/*--Assign dummy plot to create independent X2 axis--*/
scatter x=aestdate y=aeseq / markerattrs=(size=0);
refline 0 / axis=x lineattrs=(thickness=1 color=black);
/*--Assign axis properties data extents and offsets--*/
yaxis display=(nolabel noticks novalues) type=discrete;
xaxis grid label='Study Days' offsetmin=0.02 offsetmax=0.02
values=(&minday10 to &maxday by 2);
/*--Draw the legend--*/
keylegend 'sev'/ title='Severity :';
run;
Query: In the x axis scale how can we utilize maximum scale between Day -20 to Day 100 by 10 and also display the values 200 and 300 in the scale? I have tried with LOGSTYLE and LOGBASE options None did not work.
Thanks,
csa
Hello @csa,
If you want to use the log scale, then you cannot have 0 or negative numbers. You could add 1 to your AE start days and finish days. In many of my studies they also start from 1. And then you may be able to get the axis scale that you want. I also made the refline 1 instead of 0. Here is the example code:
/*--Draw the Graph--*/
ods html close;
ods graphics / reset width=5in height=3in imagename="Fig12_6_AETimeline_V93";
ods listing style=AETimelineV93 image_dpi=100;
title "Adverse Events for Patient Id = xx-xxx-xxxx";
proc sgplot data=ae2 noautolegend nocycleattrs;
/*--Draw the events--*/
highlow y=aeseq low=stday high=enday / group=aesev lowlabel=aedecod type=bar
barwidth=0.8 lineattrs=(color=black) lowcap=lcap highcap=hcap name='sev';
/*--Assign dummy plot to create independent X2 axis--*/
scatter x=aestdate y=aeseq / markerattrs=(size=0);
refline 1 / axis=x lineattrs=(thickness=1 color=black);
/*--Assign axis properties data extents and offsets--*/
yaxis display=(nolabel noticks novalues) type=discrete;
xaxis grid label='Study Days' type = log offsetmin=0.02 offsetmax=0.02 values=(1 10 20 30 40 50 60 70 80 90 100 200 300)
/*values=(&minday10 to &maxday by 2)*/;
/*--Draw the legend--*/
keylegend 'sev'/ title='Severity :';
run;
Use the VALUES= option of the XAXIS and YAXIS statements in PROC SGPLOT.
Thanks for the response. Values option already specified in the program
"xaxis grid label='Study Days' offsetmin=0.02 offsetmax=0.02
values=(&minday10 to &maxday by 2);"
Also I have tried with "xaxis grid label='Study Days' offsetmin=0.02 offsetmax=0.02
values=(-20 to 100 by 10, 200, 300);" It did not work. As in the below screenshot scale between 100-300 is equally distributed same as 0 to 100. I am trying reduce the scale between 100-300 and increase the scale between -20 to 100.
Thanks
How about trying the RANGES= option?
Hello @csa,
If you want to use the log scale, then you cannot have 0 or negative numbers. You could add 1 to your AE start days and finish days. In many of my studies they also start from 1. And then you may be able to get the axis scale that you want. I also made the refline 1 instead of 0. Here is the example code:
/*--Draw the Graph--*/
ods html close;
ods graphics / reset width=5in height=3in imagename="Fig12_6_AETimeline_V93";
ods listing style=AETimelineV93 image_dpi=100;
title "Adverse Events for Patient Id = xx-xxx-xxxx";
proc sgplot data=ae2 noautolegend nocycleattrs;
/*--Draw the events--*/
highlow y=aeseq low=stday high=enday / group=aesev lowlabel=aedecod type=bar
barwidth=0.8 lineattrs=(color=black) lowcap=lcap highcap=hcap name='sev';
/*--Assign dummy plot to create independent X2 axis--*/
scatter x=aestdate y=aeseq / markerattrs=(size=0);
refline 1 / axis=x lineattrs=(thickness=1 color=black);
/*--Assign axis properties data extents and offsets--*/
yaxis display=(nolabel noticks novalues) type=discrete;
xaxis grid label='Study Days' type = log offsetmin=0.02 offsetmax=0.02 values=(1 10 20 30 40 50 60 70 80 90 100 200 300)
/*values=(&minday10 to &maxday by 2)*/;
/*--Draw the legend--*/
keylegend 'sev'/ title='Severity :';
run;
Thanks.
X axis negative values have been converted to positive values. In graph negative values have been displayed using format.
This is an example of how you can use the OFFSETMIN (and OFFSETMAX) option:
You could use VALUESDISPLAY=() option to display 200 when it is 110, 300 when it is 120 .
values=(0 to 120 by 10) valuesdisplay=('0' '10' '20' ............... '100' '200' '300')
When you want the graph like you want the graph, I often recommend using annotate ...
Here's one way to get the values you want on the xaxis using annotate. I make the actual xaxis values 'white' (so they'll be invisible against the white background, but so they also 'reserve the space' for the labels I'm going to annotate). I've also modified your data section a bit to use a delimiter, so it will be easier for others to copy-n-paste and run.
data ae0;
retain aestdateMin;
retain aeendateMax;
attrib aestdate informat=yymmdd10. format=date7.;
attrib aeendate informat=yymmdd10. format=date7.;
length aedecod $50;
format aestdateMin aeendateMax date7.;
drop aestdateMin aeendateMax;
input aeseq aedecod $ aesev $ aestdate aeendate;
aestdateMin=min(aestdate, aestdateMin);
aeendateMax=max(aeendate, aeendateMax);
call symputx('mindate', aestdateMin);
call symputx('maxdate', aeendateMax);
y=aeseq;
if aedecod=" " then y=-9;
infile datalines dlm=':';
datalines;
.: :MILD::2013-03-06:2013-03-06:Legend
.: :MODERATE::2013-03-06:2013-03-06:Legend
.: :SEVERE::2013-03-06:2013-03-06:Legend
1:DIZZINESS:MODERATE:2013-03-06:2013-03-07:
2:COUGH:MILD:2013-03-20:.:
3:APPLICATION SITE DERMATITIS:MILD:2013-03-26:2013-06-18:
4:DIZZINESS:MILD:2013-03-27:2013-03-27:
5:ELECTROCARDIOGRAM T WAVE INVERSION:MILD:2013-03-30:.:
6:DIZZINESS:MILD:2013-04-01:2013-04-11:
7:DIZZINESS:MILD:2013-04-01:2013-11-11:
8:APPLICATION SITE DERMATITIS:MODERATE:2013-03-26:2013-06-18:
9:HEADACHE:MILD:2013-05-17:2013-05-18:
10:APPLICATION SITE DERMATITIS:MODERATE:2013-03-26:2013-06-18:
11:PRURITUS:MODERATE:2013-05-27:2013-06-18:
;
run;
data _null_;
set ae0;
minday=0;
maxday= &maxdate - &mindate;
minday10 = -20;
mindate10=&mindate - 20;
call symputx('minday', minday);
call symputx('maxday', maxday);
call symputx('minday10', minday10);
run;
data ae2; set ae0;
aestdy= aestdate-&mindate+0;
aeendy= aeendate-&mindate+0;
stday=aestdy;
enday=aeendy;
if aestdy=. then do;
stday=&minday;
lcap='ARROW';
end;
if aeendy=. then do;
enday=&maxday;
hcap='ARROW';
end;
xs=0;
run;
data anno_x_values;
do x1=-20 to 100 by 10, 200, 300;
output;
end;
run;
data anno_x_values; set anno_x_values;
length label $300 x1space y1space anchor $50;
layer="front";
function="text"; textcolor="gray33"; textsize=8;
width=100; widthunit='percent';
x1space='datavalue';
y1space='wallpercent';
anchor='top';
y1=-1;
label=trim(left(x1));
run;
ods graphics / width=900px height=600px;
proc sgplot data=ae2 noautolegend nocycleattrs sganno=anno_x_values;
highlow y=aeseq low=stday high=enday / group=aesev lowlabel=aedecod type=bar
barwidth=0.8 lineattrs=(color=black) lowcap=lcap highcap=hcap name='sev';
scatter x=aestdate y=aeseq / markerattrs=(size=0);
refline 0 / axis=x lineattrs=(thickness=1 color=black);
yaxis display=(nolabel noticks novalues) type=discrete;
xaxis valueattrs=(color=white)
label='Study Days' offsetmin=0.15 offsetmax=0.02
values=(-20 to 300 by 10);
keylegend 'sev'/ title='Severity :';
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.