BookmarkSubscribeRSS Feed
spenna
Calcite | Level 5

Dear all,

 

I am new to SAS (coming from R) and i would like to sort boxplot by the median of the variable being plotted. 

The code i have generated using SAS Enterprise is the following:

 

 

Spoiler
PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT T.Country, T.BUFF
FROM WORK.QUERY_FOR_PROFITABILITY_MI as T
WHERE BUFF BETWEEN -5 AND 5
;
QUIT;
SYMBOL1 INTERPOL=BOXTJF VALUE=CIRCLE
HEIGHT=1
MODE=EXCLUDE
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE

;
Axis2
STYLE=1
WIDTH=1
MINOR=NONE

VALUE=(ANGLE=90)
;
TITLE;
TITLE1 "Box Plot";
FOOTNOTE;
FOOTNOTE1 "Generated by the SAS System (&_SASSERVERNAME, &SYSSCPL) on %TRIM(%QSYSFUNC(DATE(), NLDATE20.)) at %TRIM(%SYSFUNC(TIME(), TIMEAMPM12.))";
PROC GPLOT DATA=WORK.SORTTempTableSorted
;
PLOT BUFF * Country/
VAXIS=AXIS1

HAXIS=AXIS2

GRID
;
/* -------------------------------------------------------------------
End of task code.
------------------------------------------------------------------- */
RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;
GOPTIONS RESET = SYMBOL;%SYMDEL _CLIENTTASKFILTER;

 

 

Is there a way to modify such code in order to get the desired order of the boxplots? 

 

Thanks for any help!

 

3 REPLIES 3
skg74_mail_umkc_edu
Obsidian | Level 7
Hello,
Can i know whether did you find out the median of the variable which you want to plot? You can use Proc univariate or Proc means in order to get a median of variable.
Ksharp
Super User

Give you an example. If you have SAS9.4 ,that would be more easy by using SQL.

 

 

 

data class;
 set sashelp.heart;
 array x{*} _numeric_;
 do i=1 to dim(x);
  vname=vname(x{i});
  value=x{i};
  output;
 end;
 keep vname value;
run;
proc sort data=class;by vname;run;
proc summary data=class;
 by vname;
 var value;
 output out=median(drop=_:) median=median;
run;
data want;
 merge class median;
 by vname;
run;
proc sort data=want;by median;run;

proc sgplot data=want ;
 vbox value/category=vname;
 xaxis discreteorder=data;
run;

 

 

x.png

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 2754 views
  • 0 likes
  • 3 in conversation