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

Hi SAS experts,

 

I'd like to display R-square or slope on the each individual poverty level specific panel in the plot below. I know that there is INSET function but I couldn't work it out. Any hints or suggestions highly appreciated?

 

SAS SUPPORT PLOT.png

 

DATA HAVE;
INPUT FIPS_TRACT AAR pover X_PRMP;
CARDS;
36001001400	32.6046	4	2.27
36001002200	42.8707	3	2.40
36001014203	37.4631	1	0.14
36003951300	46.5464	3	0.07
36005002400	0	1	0.55
36005006200	60.8516	4	0.36
36005015900	30.3371	4	0.66
36005016900	49.6429	4	0.62
36005017701	69.829	4	0.50
36005018102	44.5647	4	0.57
.....
DATA CONTINUES FOR ~5000 tracts
;

ods graphics / height=300px width=800px;
TITLE "AGE ADJ RATE VS OTHER VARS";
proc sgpanel data=HAVE;
panelby POVER / onepanel novarname ROWS=1;
reg x=X_PRMP y=AAR / cli CLM markerattrs=(size=3px);
INSET?
FORMAT POVER $POVER.;
WHERE POVER NE '99';
run;
PROC FORMAT;
value $POVER
'1'="%POVERTY <5%"
'2'="%POVERTY 5% to <10%"
'3'="POVERTY 10% to < 20%" 
'4'="POVERTY >20%"
'99'="Unknown"
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Notice the last column I added .

 

DATA HAVE;
infile cards expandtabs truncover;
INPUT FIPS_TRACT AAR pover $ X_PRMP R_Square;
CARDS;
36001001400	32.6046	1	2.27 0.8
36001002200	42.8707	1	2.40 0.8
36001014203	37.4631	1	0.14 0.8
36003951300	46.5464	1	0.07 0.8
36005002400	0	1	0.55 0.8
36005006200	60.8516	4	0.36 0.34
36005015900	30.3371	4	0.66 0.34
36005016900	49.6429	4	0.62 0.34
36005017701	69.829	4	0.50 0.34
36005018102	44.5647	4	0.57 0.34
;


PROC FORMAT;
value $POVER
'1'="POVERTY <5%"
'2'="POVERTY 5% to <10%"
'3'="POVERTY 10% to < 20%" 
'4'="POVERTY >20%"
'99'="Unknown"
;
run;



ods graphics / reset=all;
TITLE "AGE ADJ RATE VS OTHER VARS";
proc sgpanel data=HAVE;
panelby POVER / onepanel novarname ROWS=1;
reg x=X_PRMP y=AAR / cli CLM markerattrs=(size=3px);
INSET R_Square / position=top;
FORMAT POVER $POVER.;
WHERE POVER NE '99';
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User

Notice the last column I added .

 

DATA HAVE;
infile cards expandtabs truncover;
INPUT FIPS_TRACT AAR pover $ X_PRMP R_Square;
CARDS;
36001001400	32.6046	1	2.27 0.8
36001002200	42.8707	1	2.40 0.8
36001014203	37.4631	1	0.14 0.8
36003951300	46.5464	1	0.07 0.8
36005002400	0	1	0.55 0.8
36005006200	60.8516	4	0.36 0.34
36005015900	30.3371	4	0.66 0.34
36005016900	49.6429	4	0.62 0.34
36005017701	69.829	4	0.50 0.34
36005018102	44.5647	4	0.57 0.34
;


PROC FORMAT;
value $POVER
'1'="POVERTY <5%"
'2'="POVERTY 5% to <10%"
'3'="POVERTY 10% to < 20%" 
'4'="POVERTY >20%"
'99'="Unknown"
;
run;



ods graphics / reset=all;
TITLE "AGE ADJ RATE VS OTHER VARS";
proc sgpanel data=HAVE;
panelby POVER / onepanel novarname ROWS=1;
reg x=X_PRMP y=AAR / cli CLM markerattrs=(size=3px);
INSET R_Square / position=top;
FORMAT POVER $POVER.;
WHERE POVER NE '99';
run;
Cruise
Ammonite | Level 13

@Ksharp 

 

The solution worked with the given demo data. However, do you know why it doesn't work when I add one more variables into the panel statement and extend my layout to lattice?

The error I get is:

3009 ods graphics / height=400px width=800px;
3010 TITLE "AAR VS ESJCREEN";
3011 proc sgpanel data=Long_format;
3012 panelby POVER EXPOSURES /onepanel LAYOUT=LATTICE novarname ROWS=2;
3013 REG x=EJ_VALUES y=N_TRACT/ CLI CLM markerattrs=(size=3px);
3014 FORMAT POVER $POVER.;
3015 INSET R_Square / position=top;
ERROR: Variable R_SQUARE not found.
3016 run;

ods graphics / height=400px width=800px;
TITLE "AAR VS ESJCREEN";
proc sgpanel data=Long_format;
panelby POVER EXPOSURES /onepanel LAYOUT=LATTICE novarname ROWS=2;
REG x=EJ_VALUES y=N_TRACT/ CLI CLM markerattrs=(size=3px);
FORMAT POVER $POVER.;
INSET R_Square / position=top;
run;
Cruise
Ammonite | Level 13
Oops, I just noticed that you added a column with R-square. I thought R-square in INSET was built in. I think I got it. I have to calculate S-squares then use INSET.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1498 views
  • 0 likes
  • 2 in conversation