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

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.

 

Thanks in advance!

 

 
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
DanH_sas
SAS Super FREQ

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;

View solution in original post

5 REPLIES 5
DanH_sas
SAS Super FREQ

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;
shari
Calcite | Level 5

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.

 

Please let me know. 

 

Thanks again!

 

DanH_sas
SAS Super FREQ

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;
shari
Calcite | Level 5

Thank you so much!

DanH_sas
SAS Super FREQ

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.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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