/* Download the New York City CSV file from here: https://data.cityofnewyork.us/Social-Services/NYC-Wi-Fi-Hotspot-Locations/a9we-mtpn Run the program below to import the CSV data and use SGMAP */ ods _all_ close; ods html file="hotspots.html"; /* import the CSV data */ proc import datafile="u:\hotspots\NYC_Free_Public_WiFi_03292017.csv" out=hotspots dbms=csv replace; datarow=2; /* start reading the data in the second row */ getnames=yes; /* generate SAS variable names from first row */ guessingrows=20; /* 20 is the default, it works fine for this data */ run; /* Plot all of the hotspots */ title1 'New York City Wi-Fi Hotspots'; proc sgmap plotdata=hotspots noautolegend; openstreetmap; scatter x=lon y=lat; run; /**********************************************************************/ /* This section uses a neighborhood polygon provided by New York City */ /* to limit the data using PROC GINSIDE. */ /* Download the shapefile data from this web site https://data.cityofnewyork.us/City-Government/Neighborhood-Tabulation-Areas/cpf4-rkhq */ /* import the map data */ proc mapimport out=boros datafile="u:\hotspots\ny_polygons\geo_export_637f837d-f7b1-4f4e-8957-d01249086fdb.shp"; run; /* limit the polygons to the one we want */ data boros; set boros; where ntaname = "Midtown-Midtown South"; run; /* proc ginside requres that we use x and y */ data hotspots_xy(rename=(lon=x lat=y)); set hotspots(drop=x y); run; proc ginside data=hotspots_xy /* input dat set */ map=boros /* map polygon used to compare to input data */ out=hotspots_xy /* output data set */ insideonly; /* only points inside the map polygon are kept */ id boro_code; /* variable from map data set */ run; /* SAS Institute is at: 787 7th Ave # 47, New York, NY 10019 */ /* add SAS Institute to the data set */ data hotspots_xy; length saslabel $ 3.; set hotspots_xy end=eof; saslabel = ''; output; if eof then do; saslabel = "sas"; lat = 40.7618356; lon = -73.98218050000002; output; end; run; /* Plot all of the hotspots in Midtown South */ title1 'Midtown South Wi-Fi Hotspots'; title2 'SGMAP SCATTER Data Limited by PROC GINSIDE'; proc sgmap plotdata=hotspots_xy noautolegend; openstreetmap; /* this plots the location of the hotspots */ scatter x=x y=y / markerattrs=(symbol=triangledown color=red); /* this plots the location of SAS */ text x=lon y=lat text=saslabel / textattrs=(color=blue size=20); run; /*******************************************************************/ /* This section selects the markers within a radius using GEODIST */ /* SAS Institute is at: 787 7th Ave # 47, New York, NY 10019 */ /* get distance from convention center using geodist function */ data hotspots (keep=lat lon provider distance); set hotspots; distance = geodist(lat, lon, 40.7618356, -73.98218050000002, 'DM'); run; /* add SAS Institute */ data hotspots; set hotspots end=eof; output; if eof then do; saslabel = "sas"; lat = 40.7618356; lon = -73.98218050000002; distance = 0; provider=''; output; end; run; /* only keep locations close to SAS */ data hotspots; set hotspots; where distance le 0.25; run; /*** PROC SGMAP with Esri Map ***/ /* This is the beginning of the Esri URL */ %let url = http://services.arcgisonline.com/arcgis/rest/services; title1 'Wi-Fi Hotspots Close to SAS'; title2 'SGMAP SCATTER Data Limited by GEODIST Function'; proc sgmap plotdata=hotspots noautolegend; esrimap url="&url/World_Topo_Map"; /* this plots the locations of the hotspots */ scatter x=lon y=lat / group=provider nomissinggroup markerattrs=(symbol=triangledown size=10 color=red); /* this plots the location of SAS */ text x=lon y=lat text=saslabel / textattrs=(color=blue size=20); run; /* Download the New York City CSV file for sidewalk cafes from this page: https://data.cityofnewyork.us/Business/Sidewalk-Caf-Licenses-and-Applications/qcdj-rwhu */ /* import the CSV data */ proc import datafile="u:\hotspots\Sidewalk_Caf__Licenses_and_Applications.csv" out=cafes dbms=csv replace; datarow=2; getnames=yes; guessingrows=1000; /* needed to avoid errors while importing CSV file */ run; /* only keep needed variables and add distance variable */ data cafes(keep=lat lon business_name2 distance); set cafes(rename=(latitude=LAT longitude=LON)); distance = geodist( lat, lon, 40.7618356, -73.98218050000002, 'DM'); if business_name2 = '' then business_name2=business_name; business_name2=propcase(business_name2); run; /* combine the hotspots and cafes datasets */ data both; set hotspots cafes; run; /* only keep locations close to SAS */ data both; set both; where distance le 0.25; /* miles */ run; /* drop suffixes for business names */ /* look for comma and truncate */ data both; set both; if business_name2 ne '' and index(business_name2, ',')>0 then business_name2 = substr(business_name2,1,index(business_name2, ',')-1); /* rename Sgr Hospiltality Group */ if business_name2 = 'Sgr Hospitality Group' then business_name2 = 'Souvlaki GR'; run; /*** PROC SGMAP with Esri Map ***/ title1 'Wi-Fi Hotspots and Outdoor Cafes Close to SAS'; title2 'SGMAP SCATTER Data Limited by GEODIST Function'; proc sgmap plotdata=both; esrimap url="&url/World_Topo_Map"; /* this plots the locations of the hotspots */ scatter x=lon y=lat / group=provider nomissinggroup markerattrs=(symbol=triangledown size=10 color=red); /* this plots the locations of the cafes */ scatter x=lon y=lat / name='cafes' group=business_name2 nomissinggroup markerattrs=(symbol=starfilled size=20); /* this plots the location of SAS */ text x=lon y=lat text=saslabel / textattrs=(color=blue size=20); /* only include cafes in the legend */ keylegend 'cafes' / title='Sidewalk Cafes'; run; /* drop the coordinates south and west of SAS */ data both; set both; if lat ge 40.7618356 and lon ge -73.983654 then output; run; /*** PROC SGMAP with Esri Map ***/ title1 'Outdoor Cafes and Hotspots North of SAS'; title2 'SGMAP SCATTER Data Limited by GEODIST Function'; proc sgmap plotdata=both; esrimap url="&url/World_Topo_Map"; /* plot the locations of the hotspots */ scatter x=lon y=lat / group=provider nomissinggroup markerattrs=(symbol=triangledown size=10 color=red); /* plot the locations of the cafes */ scatter x=lon y=lat / name='cafes' group=business_name2 nomissinggroup markerattrs=(symbol=starfilled size=20); /* plot the location of SAS */ text x=lon y=lat text=saslabel / textattrs=(color=blue size=25); /* only include cafes in the legend */ keylegend 'cafes' / title='Sidewalk Cafes'; run; quit; ods _all_ close;