Hello,
I'm very new to this and am trying to use SAS Studio to map several coordinates. I have four different maps by zip code. I was successful in plotting the coordinates on three of the maps, but when I run the same code on the fourth map, coordinates do not display. Thanks in advance for your help.
/*Sacramento Shapefile*/
proc mapimport
datafile = "/home/username/cm480wn0393.shp"
out = sacramentocounty;
run;
/*Sacramento Data*/
data sacramentonew;
set sacramentocounty;
ZCTA5CE10 = PUT(ZIP5, $5.);
length ZCTA5CE10 $5.;
drop ZIP5;
run;
proc sort data=sacramentonew out=sacramentonew2;
by ZCTA5CE10;
run;
data sacramentodata;
merge risktime2 sacramentonew2;
by ZCTA5CE10;
run;
proc gproject data=sacramentonew2 out=sacramentonew2 degrees eastlong project=none;
id ZCTA5CE10;
run;
data latlongdata;
input lat long;
datalines;
38.6785 -121.2258
;
run;
proc gproject data=latlongdata out=latlongdata latlong degrees eastlong parmout=sacramentodata parmentry=sacramentonew2 project=none;
id;
run;
data anno_point_data; set latlongdata;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='pie'; style='psolid'; rotate=360; size=3; color='black';
run;
pattern1 value=solid color='CXADFCAE';
pattern2 value=solid color='CXD5FCAD';
pattern3 value=solid color='CXF6FCAD';
pattern4 value=solid color='CXFCDEAD';
pattern5 value=solid color='CXFCB5AD';
proc gmap map=sacramentodata data=sacramentodata anno=anno_point_data;
id ZCTA5CE10;
choro score / coutline=black levels=5;
run;
Also, since you're projecting the map and annotate data separately, you'll need to save the projection parameters from the map dataset, and use them when you project the annotate data.
Here's an example where I do this:
https://robslink.com/SAS/democd103/largest_high_school_basketball_gyms.htm
https://robslink.com/SAS/democd103/largest_high_school_basketball_gyms.sas
Specifically, pay close attention to the parmout= and parmin= and parmentry=:
proc gproject data=my_map out=my_map latlong eastlong degrees parmout=work.projparm; id statecode; run; proc gproject data=my_data out=my_data latlong eastlong degrees parmin=work.projparm parmentry=my_map; id; run;
Right after you use proc mapimport to import the shapefile, use a proc print to verify that the coordinates are unprojected coordinates. Presumably if you got all 4 maps from the same source, and the other three contained unprojected coordinates then this 4th one also does ... but try printing a few lines of the dataset just to be sure (in addition to printing a few lines of the map dataset, you might want to try printing a few lines of your other datasets just as a sanity check).
proc print data=sacramentocounty (obs=10); run;
Also, since you're projecting the map and annotate data separately, you'll need to save the projection parameters from the map dataset, and use them when you project the annotate data.
Here's an example where I do this:
https://robslink.com/SAS/democd103/largest_high_school_basketball_gyms.htm
https://robslink.com/SAS/democd103/largest_high_school_basketball_gyms.sas
Specifically, pay close attention to the parmout= and parmin= and parmentry=:
proc gproject data=my_map out=my_map latlong eastlong degrees parmout=work.projparm; id statecode; run; proc gproject data=my_data out=my_data latlong eastlong degrees parmin=work.projparm parmentry=my_map; id; run;
I don't know what it was that did the trick, but something you mentioned below worked (lol). Thanks for your help!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.