Data visualization with SAS programming

Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

What is the easiest way to indicate the mean and median values on a simple series plot like the following?

 

proc sgplot data=customer_ages;
   series x=age y=buyers;
   xaxis values=(18 to 90 by 2);
   yaxis grid;
run;

In the example above, I'd like to indicate both the mean age and median age somewhere either outside or inside the graph.  No need for reference lines, just want to show the values, such as Mean: 42.3 and Median: 40.

 

Thanks much,

 

Dave

 


Accepted Solutions
Solution
2 weeks ago
SAS Super FREQ
Posts: 877

Re: Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

Another slight variation on the INSET you might want to try is the code below. It is a "table" form of inset. Either version should work for you.

 

proc sgplot data=customer_ages;
   series x=age y=buyers;
   xaxis values=(18 to 90 by 2);
   yaxis grid;
   inset ('Mean'='42.3' 'Median'='40') / position = topright;
run;

View solution in original post


All Replies
Super User
Posts: 1,072

Re: Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

[ Edited ]

Try the inset statement in sgplot, it will insert the text inside, top right position of graph.

 

proc sgplot data=customer_ages;
   series x=age y=buyers;
   xaxis values=(18 to 90 by 2);
   yaxis grid;
inset 'Mean: 42.3' 'Median: 40 ' / position = topright;
run;

 

Thanks,
Jag
Solution
2 weeks ago
SAS Super FREQ
Posts: 877

Re: Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

Another slight variation on the INSET you might want to try is the code below. It is a "table" form of inset. Either version should work for you.

 

proc sgplot data=customer_ages;
   series x=age y=buyers;
   xaxis values=(18 to 90 by 2);
   yaxis grid;
   inset ('Mean'='42.3' 'Median'='40') / position = topright;
run;
Occasional Contributor
Posts: 14

Re: Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

Ah, so there isn't any way for SGPLOT to actually calculate the mean and median?  I'll need to pre-process the data in another step, output macro variables, and then insert the macro variable references into the SGPLOT Inset statement, correct?

 

Was hoping SGPLOT could do this for me...

 

Thanks for your responses, Jagadishkatam and DanH_sas.

 

Dave

SAS Super FREQ
Posts: 877

Re: Add Mean and Median Text Values to a Simple SGPLOT Series Plot?

Correct, but you can calculate the stats outside the procedure, set it in a macro variable(s), and use the macro variable(s) in the INSET statement.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 90 views
  • 1 like
  • 3 in conversation