<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Determine if point (lat, long) is within custom polygon in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897729#M354796</link>
    <description>&lt;P&gt;A map data set includes an identification variable to "name" or "label" a polygon. So modify the Polygon data to include an identification variable. In this case I use Polygonid.&lt;/P&gt;
&lt;PRE&gt;data Polygon;
input vertex x y ;
infile datalines delimiter="#";
polygonid=1;
datalines;
1#44.1598831520675#-79.7063565442144
2#44.2877110404308#-79.0767942900621
3#44.1184676463941#-78.3947685147305
4#43.6748950070277#-78.9806111679
5#44.1598831520675#-79.7063565442144
;
run;&lt;/PRE&gt;
&lt;P&gt;I don't know why you couldn't provide another data step with the coordinates of interest. I shortened stuff as I'm too lazy to type a bunch just for an example:&lt;/P&gt;
&lt;PRE&gt;data city;
  input city $ x y;
datalines;
citya  43.68 -79.64
cityb  43.85 -79.01
;
&lt;/PRE&gt;
&lt;P&gt;And use of Proc Ginside:&lt;/P&gt;
&lt;PRE&gt;proc ginside   data=city map=polygon out=result;
  id polygonid;
run;&lt;/PRE&gt;
&lt;P&gt;The ID variable for the polygon is added , along with other variables by default from the Map data set, to the DATA= data set in the Out= data set. If there is no match the id variable and associated other variables from the Map data set is missing. if you only want to add the Id variable use the Ginside option DROPMAPVARS .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need a 0/1 value for "inside one of the polygons in the map data set" then a pass through a data step to add/change variable values.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2023 03:15:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-10-09T03:15:50Z</dc:date>
    <item>
      <title>Determine if point (lat, long) is within custom polygon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897726#M354795</link>
      <description>&lt;P&gt;I have what seems to be a simple problem. I have a set of vertices which define a polygon on a map. I'm working with Canada.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using QGIS, here is my polygon:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASAlex101_0-1696788898236.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88710i30FD38AB61F5FC3E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASAlex101_0-1696788898236.png" alt="SASAlex101_0-1696788898236.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;QGIS can output a list of vertices of the polygon, which I put into SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Polygon;
input vertex x y ;
infile datalines delimiter="#";
datalines;
1#44.1598831520675#-79.7063565442144
2#44.2877110404308#-79.0767942900621
3#44.1184676463941#-78.3947685147305
4#43.6748950070277#-78.9806111679
5#44.1598831520675#-79.7063565442144
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want to do is let's say I have this points:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PointData;&lt;BR /&gt;length City $100.;&lt;BR /&gt;input City $ X Y;&lt;BR /&gt;infile datalines delimiter="#";&lt;BR /&gt;datalines;&lt;BR /&gt;Mississauga#43.58718486496601#-79.64392326388756&lt;BR /&gt;Ajax#43.85040430693342#-79.01840936353507&lt;BR /&gt;;&lt;BR /&gt;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to know if any of these points are in the polygon or not. In the example, Ajax is within the polygon but Mississauga is not. so I'd expect the data output to be:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASAlex101_1-1696789587464.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88711iE183CF553FEFF053/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASAlex101_1-1696789587464.png" alt="SASAlex101_1-1696789587464.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how to do this. I've looked at GINSIDE, but it seems you need an underlying map for that, and I don't know how to define a polygon within that proc. So I'm kind of lost as geocoding isn't my expertise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 18:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897726#M354795</guid>
      <dc:creator>SASAlex101</dc:creator>
      <dc:date>2023-10-08T18:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if point (lat, long) is within custom polygon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897729#M354796</link>
      <description>&lt;P&gt;A map data set includes an identification variable to "name" or "label" a polygon. So modify the Polygon data to include an identification variable. In this case I use Polygonid.&lt;/P&gt;
&lt;PRE&gt;data Polygon;
input vertex x y ;
infile datalines delimiter="#";
polygonid=1;
datalines;
1#44.1598831520675#-79.7063565442144
2#44.2877110404308#-79.0767942900621
3#44.1184676463941#-78.3947685147305
4#43.6748950070277#-78.9806111679
5#44.1598831520675#-79.7063565442144
;
run;&lt;/PRE&gt;
&lt;P&gt;I don't know why you couldn't provide another data step with the coordinates of interest. I shortened stuff as I'm too lazy to type a bunch just for an example:&lt;/P&gt;
&lt;PRE&gt;data city;
  input city $ x y;
datalines;
citya  43.68 -79.64
cityb  43.85 -79.01
;
&lt;/PRE&gt;
&lt;P&gt;And use of Proc Ginside:&lt;/P&gt;
&lt;PRE&gt;proc ginside   data=city map=polygon out=result;
  id polygonid;
run;&lt;/PRE&gt;
&lt;P&gt;The ID variable for the polygon is added , along with other variables by default from the Map data set, to the DATA= data set in the Out= data set. If there is no match the id variable and associated other variables from the Map data set is missing. if you only want to add the Id variable use the Ginside option DROPMAPVARS .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need a 0/1 value for "inside one of the polygons in the map data set" then a pass through a data step to add/change variable values.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 03:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897729#M354796</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-09T03:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if point (lat, long) is within custom polygon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897730#M354797</link>
      <description>Quite extraordinary. this looks to be the foundation of what I was looking for! &lt;BR /&gt;</description>
      <pubDate>Sun, 08 Oct 2023 19:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-if-point-lat-long-is-within-custom-polygon/m-p/897730#M354797</guid>
      <dc:creator>SASAlex101</dc:creator>
      <dc:date>2023-10-08T19:13:34Z</dc:date>
    </item>
  </channel>
</rss>

