Hi folks,
I have couple questions on the same plotting problem.
1. How to display r-square value in each panel? Insert, commented out now, works without lattice layout. But gives me an error "there is no variable R_square" after I add layout=lattice option.
2. The bottom column's intention is to show relationship of "N of cases vs N of exposure sites". Because both cases and the N of exposure sites are sparse, the plot is not being very infortive. Any alternatives to recommend to visualize this context better?
Please note that this data is only 1% random sample of my actual data.
Thanks in advance. Let me know if you suggest me to seperate this post to two for each questions asked here.
I greatly appreciate any suggestions and hints or direct help.
DATA HAVE;
INPUT GEO pover $ N EXPOSURES $ EJ_VALUES;
CARDS;
36005039 4 2 CANCER_RISK 63.2836
36005039 4 2 COUNTS_TSDF 0.0000
36007011 3 0 CANCER_RISK 22.3069
36007011 3 0 COUNTS_TSDF 0.0000
36009960 2 0 CANCER_RISK 18.1951
36009960 2 0 COUNTS_TSDF 1.0000
36017970 4 0 CANCER_RISK 38.6816
36017970 4 0 COUNTS_TSDF 1.0000
36027190 2 0 CANCER_RISK 32.9410
36027190 2 0 COUNTS_TSDF 0.0000
36029006 3 0 CANCER_RISK 35.1154
36029006 3 0 COUNTS_TSDF 0.0000
36029010 3 0 CANCER_RISK 31.6126
36029010 3 0 COUNTS_TSDF 0.0000
36039080 3 0 CANCER_RISK 20.8220
36039080 3 0 COUNTS_TSDF 0.0000
36047000 3 0 CANCER_RISK 70.9754
36047000 3 0 COUNTS_TSDF 2.0000
36047004 2 0 CANCER_RISK 63.1364
36047004 2 0 COUNTS_TSDF 4.0000
36047008 4 0 CANCER_RISK 56.5344
36047008 4 0 COUNTS_TSDF 0.0000
36047011 3 0 CANCER_RISK 62.7163
36047011 3 0 COUNTS_TSDF 0.0000
36047044 4 1 CANCER_RISK 57.5470
36047044 4 1 COUNTS_TSDF 3.0000
36047048 4 1 CANCER_RISK 52.8631
36047048 4 1 COUNTS_TSDF 0.0000
36051030 3 0 CANCER_RISK 20.6163
36051030 3 0 COUNTS_TSDF 0.0000
36059404 1 1 CANCER_RISK 45.0740
36059404 1 1 COUNTS_TSDF 0.0000
36059518 1 0 CANCER_RISK 46.2042
36059518 1 0 COUNTS_TSDF 1.0000
36061002 3 1 CANCER_RISK 75.1446
36061002 3 1 COUNTS_TSDF 0.0000
36061011 2 0 CANCER_RISK 87.4068
36061011 2 0 COUNTS_TSDF 2.0000
36061018 2 1 CANCER_RISK 82.4592
36061018 2 1 COUNTS_TSDF 1.0000
36061023 3 1 CANCER_RISK 65.9496
36061023 3 1 COUNTS_TSDF 0.0000
36063024 3 0 CANCER_RISK 22.5988
36063024 3 0 COUNTS_TSDF 2.0000
36063024 3 0 CANCER_RISK 22.7899
36063024 3 0 COUNTS_TSDF 0.0000
36067011 2 0 CANCER_RISK 33.3920
36067011 2 0 COUNTS_TSDF 0.0000
36067015 2 0 CANCER_RISK 28.8998
36067015 2 0 COUNTS_TSDF 0.0000
36069051 2 1 CANCER_RISK 20.2576
36069051 2 1 COUNTS_TSDF 0.0000
36075021 3 0 CANCER_RISK 21.6302
36075021 3 0 COUNTS_TSDF 0.0000
36077591 2 0 CANCER_RISK 19.2683
36077591 2 0 COUNTS_TSDF 0.0000
36079011 2 0 CANCER_RISK 30.6732
36079011 2 0 COUNTS_TSDF 1.0000
36081040 4 2 CANCER_RISK 63.5312
36081040 4 2 COUNTS_TSDF 0.0000
36081086 4 1 CANCER_RISK 62.9083
36081086 4 1 COUNTS_TSDF 0.0000
36081098 1 0 CANCER_RISK 46.6523
36081098 1 0 COUNTS_TSDF 1.0000
36081117 4 0 CANCER_RISK 60.2166
36081117 4 0 COUNTS_TSDF 1.0000
36081162 3 0 CANCER_RISK 55.5270
36081162 3 0 COUNTS_TSDF 1.0000
36083040 4 0 CANCER_RISK 47.1551
36083040 4 0 COUNTS_TSDF 1.0000
36085022 1 0 CANCER_RISK 45.1212
36085022 1 0 COUNTS_TSDF 1.0000
36087010 2 0 CANCER_RISK 33.8989
36087010 2 0 COUNTS_TSDF 0.0000
36089491 3 0 CANCER_RISK 24.4336
36089491 3 0 COUNTS_TSDF 1.0000
36089492 3 1 CANCER_RISK 16.8045
36089492 3 1 COUNTS_TSDF 0.0000
36093020 1 0 CANCER_RISK 34.4799
36093020 1 0 COUNTS_TSDF 0.0000
36103111 2 1 CANCER_RISK 34.6693
36103111 2 1 COUNTS_TSDF 0.0000
36103159 3 0 CANCER_RISK 25.0552
36103159 3 0 COUNTS_TSDF 0.0000
36117020 1 0 CANCER_RISK 21.9895
36117020 1 0 COUNTS_TSDF 0.0000
36119000 4 0 CANCER_RISK 60.1986
36119000 4 0 COUNTS_TSDF 0.0000
36119004 2 0 CANCER_RISK 59.4253
36119004 2 0 COUNTS_TSDF 0.0000
36119013 1 0 CANCER_RISK 34.7585
36119013 1 0 COUNTS_TSDF 1.0000
;
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 / height=400px width=800px;
TITLE "AAR VS ESJCREEN";
proc sgpanel data=HAVE;
panelby POVER EXPOSURES /onepanel LAYOUT=LATTICE novarname ROWS=2;
REG x=EJ_VALUES y=N/ CLI CLM markerattrs=(size=3px);
FORMAT POVER $POVER.;
/*INSET R_Square;*/
keylegend/ title="MYTITLE" position=bottom;
colaxis label='NAME' fitpolicy=thin valuesformat=best4.0;
rowaxis label='LABEL' grid;
title "NIKE";
WHERE POVER NOT IN ("99") OR MISSING(POVER);
run;
I solved the problem, my own lengthy and time consuming way.If nobody posts easier solution then below might give an idea that I calculated the R-square separatelt and merged to my data for plotting. The code is not intended to be exact but just for an idea that INSET recalls variables from your plot data at least when it comes to R-square for your regressions.
PROC SORT DATA=E.LONG_LUNG;
BY POVER EXPOSURES;
RUN;
ods graphics off;
ODS OUTPUT FitStatistics=FIT;
PROC REG DATA=E.LONG_LUNG;
BY POVER EXPOSURES NOTSORTED;
MODEL AAR=EJ_VALUES;
ODS TRACE ON;
WHERE POVER NE '99';
RUN;
DATA RSQUARE_LUNG(RENAME=(cValue2=R_Square));
SET FIT(KEEP=EXPOSURES DEPENDENT LABEL2 cValue2 POVER);
WHERE LABEL2 IN ("R-Square");
RUN;
DATA E.LONG_LUNG1;
MERGE E.LONG_LUNG
RSQUARE_LUNG;
BY POVER EXPOSURES ;
RUN;
ods graphics / height=500px width=1000px;
proc sgpanel data=E.Long_LUNG1;
panelby POVER EXPOSURES /onepanel LAYOUT=LATTICE novarname ROWS=2;
REG x=AAR y=EJ_VALUES/ CLI CLM markerattrs=(size=3px);
FORMAT POVER $POVER.;
INSET R_Square;
keylegend/ title="Age Adjusted Rate, per 100K" position=bottom;
colaxis label='NAME' fitpolicy=thin valuesformat=best4.0;
rowaxis label='EJSCREEN VARIABLES' grid;
TITLE "Lung and Bronchus, Age Adjusted Rate vs Select EJSCREEN Variables";
WHERE POVER NOT IN ("99") OR MISSING(POVER);
run;
I solved the problem, my own lengthy and time consuming way.If nobody posts easier solution then below might give an idea that I calculated the R-square separatelt and merged to my data for plotting. The code is not intended to be exact but just for an idea that INSET recalls variables from your plot data at least when it comes to R-square for your regressions.
PROC SORT DATA=E.LONG_LUNG;
BY POVER EXPOSURES;
RUN;
ods graphics off;
ODS OUTPUT FitStatistics=FIT;
PROC REG DATA=E.LONG_LUNG;
BY POVER EXPOSURES NOTSORTED;
MODEL AAR=EJ_VALUES;
ODS TRACE ON;
WHERE POVER NE '99';
RUN;
DATA RSQUARE_LUNG(RENAME=(cValue2=R_Square));
SET FIT(KEEP=EXPOSURES DEPENDENT LABEL2 cValue2 POVER);
WHERE LABEL2 IN ("R-Square");
RUN;
DATA E.LONG_LUNG1;
MERGE E.LONG_LUNG
RSQUARE_LUNG;
BY POVER EXPOSURES ;
RUN;
ods graphics / height=500px width=1000px;
proc sgpanel data=E.Long_LUNG1;
panelby POVER EXPOSURES /onepanel LAYOUT=LATTICE novarname ROWS=2;
REG x=AAR y=EJ_VALUES/ CLI CLM markerattrs=(size=3px);
FORMAT POVER $POVER.;
INSET R_Square;
keylegend/ title="Age Adjusted Rate, per 100K" position=bottom;
colaxis label='NAME' fitpolicy=thin valuesformat=best4.0;
rowaxis label='EJSCREEN VARIABLES' grid;
TITLE "Lung and Bronchus, Age Adjusted Rate vs Select EJSCREEN Variables";
WHERE POVER NOT IN ("99") OR MISSING(POVER);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.