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?
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;
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;
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.