Dear all,
say that I want to graph data for some European countries on a map. Each country belongs to one of the two groups.
I can do something like this:
data have;
input id $ group value;
datalines;
DE 1 100
FR 1 200
ES 2 80
PT 2 70
;
run;
proc gmap data=have map=mapsgfk.europe all;
by group;
id id;
choro value/ missing range midpoints=(50, 70, 90, 120, 150);
run;
This produces two separate maps, one for each gropup. Is it possible to plot everything on one map, distingushing groups by colour?
I think the easiest solution may be to create a recoded variable that is categorical and matched to specific patterns.
Here's an example using MAPS.Europe as I don't currently have the GFK map sets.
proc format library=work; value firstgroup 0 - 60 = '11' 60 <- 80 = '12' 80 <-105 = '13' 105<-135 = '14' 135<-high= '15' ; value scdgroup 0 - 60 = '21' 60 <- 80 = '22' 80 <-105 = '23' 105<-135 = '24' 135<-high= '25' ; value $recode '11'= " 0 - 60" '12'= " 60 - 80" '13'= " 80 -105" '14'= " 105 -135" '15'= " 135+" '21'= " 0 - 60" '22'= " 60 - 80" '23'= " 80 -105" '24'= "105 -135" '25'= "135+" ; run; data have; set maps.europe2; /* random data*/ value = round(200*rand('uniform'),10); group = rand('table',0.5,0.5); if group=1 then recode=put(value,firstgroup.); else recode = put(value,scdgroup.); ; keep id value group recode; run; proc sort data=have; by recode; run; pattern1 color= H082AA55; pattern2 color= H0829988; pattern3 color= H08288BB; pattern4 color= H08277EE; pattern5 color= H08255FF; pattern6 color= H000CC77; pattern7 color= H000BB99; pattern8 color= H00099BB; pattern9 color= H00088DD ; pattern10 color= H00066FF; proc gmap map=maps.europe data=have; id id; choro recode / ; format recode $recode.; label recode='Some description'; run; quit;
This approach uses a feature where leading blank characters of a format are sort of ignored by the legend to get similar appearing labels for differenct actual values of the format. If the format for recode is not set up that way then the Format will regroup the values to have different ranges.
If you have regions, such as multiple countries comprise "east" and "west" or "north" and "south" or something similar you will need a map boundary data set for the regions and an ID variable to identify which region.
Proc Greduce can combine areas and add the ID variable.
Then your code would look something like:
proc gmap data=have map=regionmap all; id group; choro value/ missing range midpoints=(50, 70, 90, 120, 150); run;
But what your data and midpoints look like make me suspect that you want something a little more complex.
How do you want to differentiate your group on the map from the value midpoints?
You're right - it's not an easy east-west or north-south comparison. I have e.g. Finland and Spain in one group. I would like to have the same "colour intensity" and midpoints (and intensity) to be set for all countrie.
In the example above, suppose that the value of the plot variable for ES is 200. So we have two countries (FR and ES) with the same value of the variable, but belonging to different groups. I would like to have FR marked with dark-blue and ES marked with e.g. dark-red (what is important - the intensity of the blue and red should be the same). In the end I would like the map to look more or less like the one attached (I've created this manually, so the shades of each colour may not be matching ideally, but you can see the dark red/blue colour for ES and FR and the light blue/red colour for DE and PT)
Edit: Can I change the colour assigned to each country on a map? Can I do something similar to annotating sgplot graph (e.g. to plot scatter with different marker colours for different groups)? I could then use proc gmap without "by" and change the colour scheme for selected countries
Edit2: I meant something like the code below. Obviously, makrecolor is not useful here, I'd need something different . Is it possible to annotate gmap in this way?
data attrmap;
input id $ value markercolor $ ;
datalines;
myid 1 red
myid 2 blue
;
run;
proc sgplot data=have dattrmap=attrmap;
scatter x=id y=value/group=group markerattrs=(symbol=DiamondFilled) attrid=myid ;
run;
I think the easiest solution may be to create a recoded variable that is categorical and matched to specific patterns.
Here's an example using MAPS.Europe as I don't currently have the GFK map sets.
proc format library=work; value firstgroup 0 - 60 = '11' 60 <- 80 = '12' 80 <-105 = '13' 105<-135 = '14' 135<-high= '15' ; value scdgroup 0 - 60 = '21' 60 <- 80 = '22' 80 <-105 = '23' 105<-135 = '24' 135<-high= '25' ; value $recode '11'= " 0 - 60" '12'= " 60 - 80" '13'= " 80 -105" '14'= " 105 -135" '15'= " 135+" '21'= " 0 - 60" '22'= " 60 - 80" '23'= " 80 -105" '24'= "105 -135" '25'= "135+" ; run; data have; set maps.europe2; /* random data*/ value = round(200*rand('uniform'),10); group = rand('table',0.5,0.5); if group=1 then recode=put(value,firstgroup.); else recode = put(value,scdgroup.); ; keep id value group recode; run; proc sort data=have; by recode; run; pattern1 color= H082AA55; pattern2 color= H0829988; pattern3 color= H08288BB; pattern4 color= H08277EE; pattern5 color= H08255FF; pattern6 color= H000CC77; pattern7 color= H000BB99; pattern8 color= H00099BB; pattern9 color= H00088DD ; pattern10 color= H00066FF; proc gmap map=maps.europe data=have; id id; choro recode / ; format recode $recode.; label recode='Some description'; run; quit;
This approach uses a feature where leading blank characters of a format are sort of ignored by the legend to get similar appearing labels for differenct actual values of the format. If the format for recode is not set up that way then the Format will regroup the values to have different ranges.
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 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: