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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Needs not totally clear, and an example would be welcome, but have you tried:

- Assigning a format ?

- Rounding the value ?

 

Rajkaht
Calcite | Level 5

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

ballardw
Super User

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.

 

Rajkaht
Calcite | Level 5

Hi @ballardw,

 

Thank you for your help, it works.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1045 views
  • 1 like
  • 3 in conversation