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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

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

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;
doesper
Obsidian | Level 7

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

DanH_sas
SAS Super FREQ

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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