BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csa
Fluorite | Level 6 csa
Fluorite | Level 6

Hi All,

 

By using below code I am getting the following output.

csa_1-1629049380589.png

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

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;

Bar chart range.png

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

Use the VALUES= option of the XAXIS and YAXIS statements in PROC SGPLOT.

--
Paige Miller
csa
Fluorite | Level 6 csa
Fluorite | Level 6

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.

csa_0-1629052042684.png

Thanks

PaigeMiller
Diamond | Level 26

How about trying the RANGES= option?

--
Paige Miller
csa
Fluorite | Level 6 csa
Fluorite | Level 6
RANGES option has unnecessary extra line between values 100 - 200, also not displaying the tick values between -20 to 100 by 10.
djrisks
Barite | Level 11
You can use the RANGES and the VALUES option together, so that the values -20 to 100 are still shown.
djrisks
Barite | Level 11

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;

Bar chart range.png

csa
Fluorite | Level 6 csa
Fluorite | Level 6

Thanks.

X axis negative values have been converted to positive values. In graph negative values have been displayed using format.

djrisks
Barite | Level 11
You're welcome! That's a great solution!

Also, if you are creating negative values just so that you can display the "DIZZINESS" AE text. You could also just increase the OFFSETMIN from 0.02 to 0.1, and that will display the complete AE name.
djrisks
Barite | Level 11

This is an example of how you can use the OFFSETMIN (and OFFSETMAX) option:

 

example range2.png

Ksharp
Super User

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')

GraphGuy
Meteorite | Level 14

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;

SGPlot28.png

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 14259 views
  • 8 likes
  • 5 in conversation