I am using PROC SGMAP to spatially plot locations of air-bnbs in San Francisco. I am trying to color code the points based on reviews (i.e. red=poor, yellow=standard, and green=excellent). Using this code:
proc sgmap plotdata=checkout.airbnb_SF;
ESRIMAP URL = 'https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer';
scatter X = longitude Y = latitude / group=score_class markerattrs=(symbol=circlefilled size=5) transparency=0.6;
run;
I am able to produce a plot with the default colors:
I have tried using style modification:
proc template;
define style MyStyle;
parent = Styles.Listing;
/* Attempt to change to different colors */
class GraphData1 / contrastcolor = GraphColors('gcdata4');
class GraphData2 / contrastcolor = GraphColors('gcdata5');
class GraphData3 / contrastcolor = GraphColors('gcdata6');
end;
run;
ods listing style=MyStyle;
proc sgmap plotdata=checkout.airbnb_SF;
ESRIMAP URL = 'https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer';
scatter X = longitude Y = latitude / group=score_class markerattrs=(symbol=circlefilled size=5) transparency=0.6;
run;
and %Modstyle:
%modstyle
(name=MyStyle
,parent=Listing
,type=CLM
,colors=cx543005 cx9D3CDB cx7F8E1F
);
ods listing style=MyStyle;
proc sgmap plotdata=checkout.airbnb_SF;
ESRIMAP URL = 'https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer';
scatter X = longitude Y = latitude / group=score_class markerattrs=(symbol=circlefilled size=5) transparency=0.6;
run;
However, the default colors do not change. Using STYLEATTRS yields an error that the "Statement is not valid or it is used out of proper order":
proc sgmap plotdata=checkout.airbnb_SF_Train;
STYLEATTRS DATACOLORS=(green, yellow, red);
ESRIMAP URL = 'https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer';
scatter X = longitude Y = latitude / group=score_class markerattrs=(symbol=circlefilled size=5) transparency=0.6;
run;
I also tried using an attribute map, but proc sgmap did not like the inclusion of dattrmap=<my attribute map>. I'm at a loss of what else to try to change the color defaults.
For now, you will have to use the custom style approach. Your style definition works for me. Do you happen to also have ODS HTML open, and you are looking at the HTML output instead of the LISTING output?
BTW, both the STYLEATTRS statement and attribute map support will be in the next release for SGMAP.
What version of SAS 9.4 are you using -- 9.4m5 or 9.4m6?
You can use:
%put &sysvlong;
to show the version. Just post the output from the log here. Thanks!
I am not as familiar with SGMAP features. However, one workaround to try is to restructure your Airbnb data in "Wide" format, like Excel. One column per type (Poor, Standard, Excellent). Use missing values where needed. Then, you can use three separate scatter statements, one per column, and set the colors explicitly.
For now, you will have to use the custom style approach. Your style definition works for me. Do you happen to also have ODS HTML open, and you are looking at the HTML output instead of the LISTING output?
BTW, both the STYLEATTRS statement and attribute map support will be in the next release for SGMAP.
I wasn't looking at the HTML output -- thank you for pointing that out!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.