DATA Step, Macro, Functions and more

Proc gmap for longitude latitude data of a city

Reply
Occasional Contributor
Posts: 7

Proc gmap for longitude latitude data of a city

Hello Community,

 

I am using Base SAS to analyze a crime dataset related to one of the cities of US. I have a dataset that has x-coordinate, y-coordinate, longitude, and latitude data related to the city. Can I use Proc gmap or any other function to map these crime locations for this city? 

 

I am stuck and I could not proceed ahead with it. Again, I am aware of SAS visual analytics but that is not what I want to use. I want this to be done through Base SAS. Please provide some help. 

 

Thank you in advance.

 

PROC Star
Posts: 2,317

Re: Proc gmap for longitude latitude data of a city

[ Edited ]
Posted in reply to aaaaaaaa21

You need SAS/Graph, which comes with mapping data sets.

When you have this, see here.

Occasional Contributor
Posts: 7

Re: Proc gmap for longitude latitude data of a city

Thank you for the information. I have the SAS/Graph. But I am still not sure which statement to use to run my longitude and latitude (or my x and y-coordinates). If you do not mind, can you give me an example of a statement where I can use longitude and latitude (or my x and y-coordinates)?
PROC Star
Posts: 2,317

Re: Proc gmap for longitude latitude data of a city

Posted in reply to aaaaaaaa21

Have you tried and looked at the examples?

Occasional Contributor
Posts: 7

Re: Proc gmap for longitude latitude data of a city

I did. I went through the third edition (the link you provided). I actually had already went through it a few days back too. I searched through the search box - I came across several examples that usese longitutde and latitude. But all of them either have Zipcode along with it or are used to trim a given map. In my case, I have the dataset related to San Fransisco, for each date (01/01/2018) and for those dates, I have crime types, where the crime happened (interms of longitude and latitude; x and y-coordinates). This data is in excel file. Now, I know how to draw a .shp file or use a zipcode for mapping. I know how to use SAS VA too. However, I did not find an example of how to create a map/graph based on those limited information. Any suggestions will be appreciated.
PROC Star
Posts: 2,317

Re: Proc gmap for longitude latitude data of a city

Posted in reply to aaaaaaaa21
I'm not even at work to help you, but a Google search brings heaps of examples like this one.
https://stackoverflow.com/questions/42077817/map-latitude-and-longitude-to-state-in-sas
SAS Employee
Posts: 1,037

Re: Proc gmap for longitude latitude data of a city

Posted in reply to aaaaaaaa21

I am assuming that you have imported the shapefile for the city (using Proc Mapimport), and have projected the lat/long values to get projected y/x values (using Proc Gproject).

 

When you do the above, you can use Proc Gproject's parmout= option, and save the projection parameters, to use in the next step...

 

Now you can take your crime lat/long dataset, and project it using Proc Gproject, and use the same projection parameters as you used for the city map (by using Gproject's parmin= option). And then use those projected x/y coordinates, and use them to annotate markers on the map. You could either use the annotate function='label' and annotate symbols from a font, or use the annotate function='pie' to annotate colored bubbles.

 

Here's an example that uses the parmout and parmin, that might help get you started...

http://robslink.com/SAS/democd95/scottish_festivals_nc_info.htm

 

Occasional Contributor
Posts: 15

Re: Proc gmap for longitude latitude data of a city

Posted in reply to RobertAllison_SAS

/*Here's an example from Central Texas Ya'll*/Robot wink

 

/*This example shows how to convert GPS to planar, and then gplot 

/*Create a sample data set a location in Central Texas - Google says this is Austin*/
data have;
input lat long POINT_ID;
datalines;
30.2272 -97.7431 1
;
run;

/*Project Lat Long onto Central Texas Map - See Sashelp.Proj4def */


/*Project your lat long onto NAD 1983 StatePlane Texas Central FIPS 4203 Feet*/
/*Parameters: +proj=lcc +lat_1=30.11666666666667 +lat_2=31.88333333333333 +lat_0=29.66666666666667
+lon_0=-100.3333333333333 +x_0=700000 +y_0=3000000 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 no_defs*/
proc gproject latlon
project=proj4 to="ESRI:102739" /*NAD 1983 StatePlane Texas Central FIPS 4203 Feet*/
data=have out=want;
id POINT_ID; 
run;

/*Now plot using sgplot*/

proc sgplot data=want;

    scatter x=x y=y;

    run;

 

/*But wait - there's more...*/

/*You can download public maps (.gov websites usually have these) as shapefiles and convert them to your local planar coordinate system*/

PROC MAPIMPORT OUT=<your filename here> DATAFILE='<public shapefile here>.shp';
run;

 

/*Check - You must call lat long 'lat' 'long' before you can proc gproject...if not rename them*/

 

/*Convert Shape file map to Central Texas State Plane*/
proc gproject latlon
project=proj4 to="ESRI:102739" /*NAD 1983 StatePlane Texas Central FIPS 4203 Feet*/
data=<your filename here> out=<file with planar coordinates>;
id SHAPE_ID; /*SHAPE_ID is the field common to all the points that define a shape*/
run;

/*Now concatenate the point and the shape file - Note You will need to rename the X and Y in your points file, call them XP and YP*/

data combined; set want <file with planar coordinates>; run;
proc sgplot data=combined;
polygon x=x y=y ID=SHAPE_ID / fill outline;
scatter x=XP y=YP;
run;

/*Even cooler...You can also use proc ginside to see if your point lies inside any of the shapes from your shape file...for example*/

proc ginside data=want map=<your filename> out=Inside INSIDEONLY;

   id SHAPE_ID;

   run;

Bread Crumbs and Circuses for All
Ask a Question
Discussion stats
  • 7 replies
  • 163 views
  • 0 likes
  • 4 in conversation