Hello,
I am using gmap procedures to produce maps of the estimates of a model. SAS by default generates the range of these estimates and I can manage the levels but I could be able to manage the digits "decimals" of the estimates. I want to show only 2-digits in the values of the legend.
is there a way to add it to the code?
I appreciate any help.
thank you
here is my code
%macro map(data=,var=);
goptions reset=all;
proc gmap data=&data map=results all ;
id gc;
choro &var / legend=legend1 LEVELS=5;
legend1 position=( bottom right inside ) offset=(1.2cm ,0cm ) shape=bar(2,1) across=1 mode=PROTECT label=none / value=(h=0.8 f=swissb justify=left);
run;
quit;
%mend map;
I would start by applying a format to the variable that displays the with the desired appearance.
An example where I make an generic data set to actually display something and two versions of a minimal Gmap call to demonstrate the difference a format can make:
proc sql; create table work.statedata as select statecode, rand('uniform') as val from (select distinct statecode from maps.us) ; quit; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/levels=5; run; quit; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/levels=5; format val f4.2; run; quit;
I might suggest using a custom format as the above example is likely to generate end points that appear in multiple levels and/or have gaps.
Here's a brief example:
proc format library=work; value mylev 0 - 0.2 = ' 0 - 0.20' 0.2 <- 0.4 = '0.2 < 0.4' 0.4 <- 0.6 = '0.4 < 0.6' 0.6 <- 0.8 = '0.6 < 0.8' 0.8 <- 1.0 = '0.8 < 1' ; run; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/discrete; format val mylev.; run; quit;
Notice use of discrete instead of levels. The above has an additional advantage that you could change the groupings just by either changing the definition of the format or using a different format and not having to adjust the number of levels. This does change to using a discrete color system which would follow pattern definitions instead of a color ramp.
Needs not totally clear, and an example would be welcome, but have you tried:
- Assigning a format ?
- Rounding the value ?
Hello @ChrisNZ,
I appreciate your response. I do not know how to round within the code. Is it possible inside the code or should I round the values of the outputs first?
I want to map specific outputs of a regression model e.g., residuals, please find the legend attached. however i want the values to be rounded to only 2-digits (i.e., 0.53-0.67, 0.67-0.73, 0.73-0.80, 0.80-0.88)
Thank you
I would start by applying a format to the variable that displays the with the desired appearance.
An example where I make an generic data set to actually display something and two versions of a minimal Gmap call to demonstrate the difference a format can make:
proc sql; create table work.statedata as select statecode, rand('uniform') as val from (select distinct statecode from maps.us) ; quit; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/levels=5; run; quit; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/levels=5; format val f4.2; run; quit;
I might suggest using a custom format as the above example is likely to generate end points that appear in multiple levels and/or have gaps.
Here's a brief example:
proc format library=work; value mylev 0 - 0.2 = ' 0 - 0.20' 0.2 <- 0.4 = '0.2 < 0.4' 0.4 <- 0.6 = '0.4 < 0.6' 0.6 <- 0.8 = '0.6 < 0.8' 0.8 <- 1.0 = '0.8 < 1' ; run; proc gmap data=work.statedata map=maps.us ; id statecode; choro val/discrete; format val mylev.; run; quit;
Notice use of discrete instead of levels. The above has an additional advantage that you could change the groupings just by either changing the definition of the format or using a different format and not having to adjust the number of levels. This does change to using a discrete color system which would follow pattern definitions instead of a color ramp.
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.