BookmarkSubscribeRSS Feed
Quentin
PROC Star

Was playing with SGPANEL, using the INSET statement to show some summary statistics, .e.g.:

 

proc sql ;
  create table class as
  select *
        ,mean(height) as meanheight
        ,mean(weight) as meanweight
  from sashelp.class 
  group by sex
 ;
quit ; 

proc sgpanel data=class ;
  panelby sex / rows=2 layout=rowlattice noheader spacing=10;
  scatter x=height y=weight;
  inset meanheight meanweight;
run ;

Works grand.  Then I thought sometimes I don't want a panel, I just want SGPLOT.  But unfortunately, below errors because in SGPLOT, you need to specify a text literal value for an INSET, you can't specify a variable name:

 

proc sgplot data=class ;
  scatter x=height y=weight;
  inset meanheight meanweight; *cant use a variable here ;
  where sex='M' ;
run ;

 

I guess to use the INSET statement in SGPLOT, I'll have to create macro variables with the values.

 

This bugs me, does it bug anyone else, to the point where it's worth submitting a ballot item?  Am I missing some obvious way to get a simple INSET box from SGPLOT.  (I suppose I could use SGANNO, but INSET is so simple. )

 

 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
5 REPLIES 5
PaigeMiller
Diamond | Level 26

I would like to see INSET allow variables as well, and in such a way that when you need to do a PLOT with a BY statement, INSET will choose the proper values based upon the BY variable(s).

--
Paige Miller
Quentin
PROC Star

Good point about supporting BY statement, @PaigeMiller .

 

Maybe a workaround to consider is to use SGPANEL with just one cell.  It seems happy to honor the BY statement:

 

proc sgpanel data=class ;
  panelby sex / rows=1 layout=rowlattice;
  scatter x=height y=weight;
  inset meanheight meanweight;
  by sex ;
run ;
Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
DanH_sas
SAS Super FREQ

If variable support was added to SGPLOT's INSET statement, what would be the desired behavior?

1. Have INSET take two columns (label/values), and generate one inset with all values?

2. Support label/value variables only when a BY-group is active, and display the pairs from each BY-group?

 

If you create a ballot item for this, the answer to questions like these would be good feedback to have.

 

Thanks!
Dan

Quentin
PROC Star

Thanks for the questions @DanH_sas ,

 

I think I would want the SGPLOT inset to allow a variable list, with the same rules as the SGPANEL inset, for consistency sake. So just one variable per label/value pair:

INSET variable <…variable-n> </options> ;
specifies one or more variables to use for the data-driven text inside the inset. Typically, the variable is a computed numeric value, such as a mean or a sum.
For non-computed variables, the statement displays the value of the first observation for each classification.
The inset labels are derived from the variable labels, or variable names if the labels are not present. (You can suppress the labels using the NOLABEL option.) The inset values come from the variable data.

So basically extending the SGPLOT inset from:

INSET "text-string" <… "text-string-n"> </options>;

To:

INSET "text-string" <… "text-string-n"> |  variable <…variable-n> </options>;

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
PaigeMiller
Diamond | Level 26

@DanH_sas 

 

This thread is a good example of why such a feature is needed: https://communities.sas.com/t5/SAS-Programming/the-code-is-not-displaying-the-correct-information-on...

 

Not only is it inefficient to bypass using the BY statement, so now the program has to read the data set in question in its entirety in each loop of the macro, but many people cannot write such a macro to do this, and I'm sure there are many SAS users who would not even know that a macro could be used here.

--
Paige Miller

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
  • 5 replies
  • 231 views
  • 4 likes
  • 3 in conversation