Calcite | Level 5

## Line plot of median with IQR

Hi all,

I am trying to create a line plot of median with IQR for each armcd by visit. I am able to get the result but in three different figures for three arms unlike in one figure with all the three arms. Is there any way to get the three arm groups data in one plot. below is the code. Please let me know.

data stats;
input @1 avisit \$10. @9 avisitn armn armcd \$ median q1 q3;
datalines;
Baseline  0 60 DummyA 5639 2909 7221.5
Baseline  0 70 DummyB 3876 2929 6587
Baseline  0 80 DummyC 5112 3284 6686
Week1     12 60 DummyA 3304 1961 6157.5
Week12   12 70 DummyB 3496 1717 5021.5
Week12   12 80 DummyC 4266.5 3436 6504.5
Week26   26 60 DummyA 3762 2409 6233
Week26   26 70 DummyB 4377 3380 6735
Week26   26 80 DummyC 4261 3242 6084
;
run;

data reshape;
set stats;
yvar=median;
output;
yvar=q1;
output;
yvar=q3;
output;
run;

/* Define the axis characteristics */
axis1 offset=(5,5) minor=none order=(0 12 26);
/* Define the symbol characteristics */
symbol1 interpol=hiloctj color=blue line=2;
symbol2 interpol=none color=blue value=dot height=1.5;

proc sort data = reshape; by armcd; run;

proc gplot data=reshape;
by armcd;
plot yvar*avisitn median*avisitn / overlay haxis=axis1 vaxis=axis2;
run;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: Line plot of median with IQR

Sure, just use PROC SGPLOT for that:

``````data stats;
input @1 avisit \$10. @9 avisitn armn armcd \$ median q1 q3;
datalines;
Baseline  0 60 DummyA 5639 2909 7221.5
Baseline  0 70 DummyB 3876 2929 6587
Baseline  0 80 DummyC 5112 3284 6686
Week1     12 60 DummyA 3304 1961 6157.5
Week12   12 70 DummyB 3496 1717 5021.5
Week12   12 80 DummyC 4266.5 3436 6504.5
Week26   26 60 DummyA 3762 2409 6233
Week26   26 70 DummyB 4377 3380 6735
Week26   26 80 DummyC 4261 3242 6084
;
run;

proc sort data=stats out=sorted; by avisitn armcd; run;

proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd;
run;``````
5 REPLIES 5
SAS Super FREQ

## Re: Line plot of median with IQR

PROC SGPANEL should work well for you. Try the code below and see if it is what you want.

Hope this helps!

Dan

``````data stats;
input @1 avisit \$10. @9 avisitn armn armcd \$ median q1 q3;
datalines;
Baseline  0 60 DummyA 5639 2909 7221.5
Baseline  0 70 DummyB 3876 2929 6587
Baseline  0 80 DummyC 5112 3284 6686
Week1     12 60 DummyA 3304 1961 6157.5
Week12   12 70 DummyB 3496 1717 5021.5
Week12   12 80 DummyC 4266.5 3436 6504.5
Week26   26 60 DummyA 3762 2409 6233
Week26   26 70 DummyB 4377 3380 6735
Week26   26 80 DummyC 4261 3242 6084
;
run;

proc sgpanel data=stats;
panelby armcd / novarname;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9);
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2);
run;``````
Calcite | Level 5

## Re: Line plot of median with IQR

Thank you so much for the reply.

But would like to know if it is possible to get all the three treatments in a single graph with the different labels for different treatments unlike three panels for three treatments.

Thanks again!

SAS Super FREQ

## Re: Line plot of median with IQR

Sure, just use PROC SGPLOT for that:

``````data stats;
input @1 avisit \$10. @9 avisitn armn armcd \$ median q1 q3;
datalines;
Baseline  0 60 DummyA 5639 2909 7221.5
Baseline  0 70 DummyB 3876 2929 6587
Baseline  0 80 DummyC 5112 3284 6686
Week1     12 60 DummyA 3304 1961 6157.5
Week12   12 70 DummyB 3496 1717 5021.5
Week12   12 80 DummyC 4266.5 3436 6504.5
Week26   26 60 DummyA 3762 2409 6233
Week26   26 70 DummyB 4377 3380 6735
Week26   26 80 DummyC 4261 3242 6084
;
run;

proc sort data=stats out=sorted; by avisitn armcd; run;

proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd;
run;``````
Calcite | Level 5

## Re: Line plot of median with IQR

Thank you so much!

SAS Super FREQ

## Re: Line plot of median with IQR

For your use case, you might also want to add CURVELABELLOC=outside to the SERIES plot to move the labels outside with some collision avoidance. Give it a try and see what you think.

Discussion stats
• 5 replies
• 2303 views
• 0 likes
• 2 in conversation