Hello Everyone,
I am currently trying to create a bubble plot that is gradient-filled by a specific numeric measure. Below is the code I am trying to run as well as code for a map without gradient colors for the purpose of looking at the sample data:
/* Sample Data: rx_x = longitude rx_y = latitude Rx_State = state in which a pharmacy is located num_claims = total number of claims at a pharmacy sample_num = what I want to create the gradient by Rx_ID = ID that corresponds to a pharmacy Rx_Type = type of pharmacy NOTE: the sample data consists of 4 pseudo pharmacies and do not correspond to any real data */ DATA sample; input rx_x rx_y Rx_State $ num_claims sample_num Rx_ID Rx_Type $; CARDS; -73.791809 40.922794 NY 600 0.87 115616 A -73.836815 40.916695 NY 249 0.98 256156 A -78.710464 43.170048 NY 105 0.70 615444 B -95.300003 32.349998 TX 516 0.66 256455 B ; RUN; *gradient map attempt; %let url = http://services.arcgisonline.com/arcgis/rest/services; PROC SGMAP plotdata=sample (where=(Rx_State="NY")); esrimap url="&url/World_Topo_Map"; title H=2 'Generic Sample Title'; bubble x=rx_x y=rx_y size=num_claims / bradiusmin=1 bradiusmax=10 colorresponse=sample_num colormodel=(yellow orange red) name='bub' transparency=0.40; gradlegend 'bub'; RUN; quit; ods html close; *working map code; %let url = http://services.arcgisonline.com/arcgis/rest/services; PROC SGMAP plotdata=sample (where=(Rx_State="NY")); esrimap url="&url/World_Topo_Map"; title H=2 'Generic Sample Title'; bubble x=rx_x y=rx_y size=num_claims / bradiusmin=1 bradiusmax=10 group=Rx_Type transparency=0.4; RUN; quit; ods html close;
When I run the color gradient version of the map I get a syntax error because, according to the documentation here:
The COLORRESPONSE argument is under version SAS Viya 3.5, Post-9.4M6.
So I was wondering if it was possible to create a bubble map with gradient fill without the use of colorresponse, or without the use of Viya 3.5 or upgrading SAS releases?
I have been in contact with SAS support, and the solution seems to be that, instead of using gradient fill, I should use the GROUP argument in PROC SGMAP to color the bubbles by a custom group:
data cities; length city $20; input y x city $; state=37; value=rand('integer',1,50); cards; 35.783411 -78.79892 Cary 36.0789 -79.826888 Greensboro 35.19755 -80.834514 Charlotte ; run; data nc; set mapsgfk.us_counties; where state=37; run; ods path(prepend) work.tempat(update); proc template; define style mystyle; parent=styles.htmlblue; style graphdata1 from graphdata1 / color=cxdeebf7; style graphdata2 from graphdata2 / color=cx9ecae1; style graphdata3 from graphdata3 / color=cx3182bd; end; run; ods html style=mystyle; proc sgmap mapdata=nc plotdata=cities; choromap / mapid=id ; bubble x=x y=y size=value / group=value; run;
Thank you, Marcia Surratt!
I did come across another potential solution that involves using PROC IML In order to utilize R's graphing functionality: https://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_r_toc.htm
Which specific version of SAS are you running?
If you aren't sure run this code:
%put &sysvlong;
then look in the LOG and post the result. It would look something like
9.04.01M4P110916
It is always a good idea when asking about any error to copy the code and all the error messages from the log and paste into a text box opened on the forum with the </> icon that appears above the message window.
The SAS version is in the subject line.
SAS Log:
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR 24 25 GOPTIONS ACCESSIBLE; 26 %let url = http://services.arcgisonline.com/arcgis/rest/services; 27 PROC SGMAP plotdata=sample (where=(Rx_State="NY")); 28 esrimap url="&url/World_Topo_Map"; SYMBOLGEN: Macro variable URL resolves to http://services.arcgisonline.com/arcgis/rest/services 29 title H=2 'Generic Sample Title'; 30 bubble x=rx_x y=rx_y size=num_claims / bradiusmin=1 bradiusmax=30 31 colorresponse=num_claims colormodel=(yellow orange red) name='bub' transparency=0.40; _____________ 22 76 ERROR 22-322: Syntax error, expecting one of the following: ;, BRADIUSMAX, BRADIUSMIN, CM, DATALABEL, DATALABELATTRS, DATALABELPOS, FILL, FILLATTRS, GROUP, IN, LEGENDLABEL, MM, NAME, NOFILL, NOMISSINGGROUP, OUTLINE, PCT, PT, PX, TRANSPARENCY. ERROR 76-322: Syntax error, statement will be ignored. 32 gradlegend 'bub'; 33 RUN; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SGMAP used (Total process time): real time 0.02 seconds user cpu time 0.00 seconds system cpu time 0.03 seconds memory 544.37k OS Memory 32408.00k Timestamp 09/22/2021 03:53:15 PM Step Count 3028 Switch Count 1
I have been in contact with SAS support, and the solution seems to be that, instead of using gradient fill, I should use the GROUP argument in PROC SGMAP to color the bubbles by a custom group:
data cities; length city $20; input y x city $; state=37; value=rand('integer',1,50); cards; 35.783411 -78.79892 Cary 36.0789 -79.826888 Greensboro 35.19755 -80.834514 Charlotte ; run; data nc; set mapsgfk.us_counties; where state=37; run; ods path(prepend) work.tempat(update); proc template; define style mystyle; parent=styles.htmlblue; style graphdata1 from graphdata1 / color=cxdeebf7; style graphdata2 from graphdata2 / color=cx9ecae1; style graphdata3 from graphdata3 / color=cx3182bd; end; run; ods html style=mystyle; proc sgmap mapdata=nc plotdata=cities; choromap / mapid=id ; bubble x=x y=y size=value / group=value; run;
Thank you, Marcia Surratt!
I did come across another potential solution that involves using PROC IML In order to utilize R's graphing functionality: https://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_r_toc.htm
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.