<?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 Compute Cumulative Distance between longitude/latitude points in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683790#M207140</link>
    <description>&lt;P&gt;Dear Forum,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have yet been able to devise a working piece of code that will create a cumulative total column that resets at each break in another variable. Have over 7k in observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, given the following sample data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp; ZIPCODE #&amp;nbsp; &amp;nbsp; long#&amp;nbsp; lat#&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp;long#&amp;nbsp; lat#&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;10&amp;nbsp; LA&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will like to compute the cumulative distance (measured in kilometers) between each of the ZIP codes in each state. With the total cumulative distance being shown in the last observation of the given state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Sep 2020 22:20:47 GMT</pubDate>
    <dc:creator>Garzaluis998</dc:creator>
    <dc:date>2020-09-14T22:20:47Z</dc:date>
    <item>
      <title>Compute Cumulative Distance between longitude/latitude points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683790#M207140</link>
      <description>&lt;P&gt;Dear Forum,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have yet been able to devise a working piece of code that will create a cumulative total column that resets at each break in another variable. Have over 7k in observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, given the following sample data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp; ZIPCODE #&amp;nbsp; &amp;nbsp; long#&amp;nbsp; lat#&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp;long#&amp;nbsp; lat#&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp;NY&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp;LA&amp;nbsp; &amp;nbsp; ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;10&amp;nbsp; LA&amp;nbsp; &amp;nbsp;ZIPCODE#&amp;nbsp; &amp;nbsp; &amp;nbsp; long#&amp;nbsp; &amp;nbsp;lat#&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will like to compute the cumulative distance (measured in kilometers) between each of the ZIP codes in each state. With the total cumulative distance being shown in the last observation of the given state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 22:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683790#M207140</guid>
      <dc:creator>Garzaluis998</dc:creator>
      <dc:date>2020-09-14T22:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Cumulative Distance between longitude/latitude points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683794#M207144</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by state;
    if first.state then cum_dist=0;
    cum_dist+geodist(lat,long,lag(lat),lag(long));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumes your data is sorted properly by state.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 22:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683794#M207144</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-14T22:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Cumulative Distance between longitude/latitude points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683801#M207150</link>
      <description>&lt;P&gt;Or possibly&lt;/P&gt;
&lt;PRE&gt;data want;
    set have;
    by state;
    if first.state then cum_dist=0;
    else cum_dist+zipcitydistance(zipcode,lag(zipcode));
run;&lt;/PRE&gt;
&lt;P&gt;Depending on where you obtained the lat and long values the ZIPCITYDISTANCE likely varies as it uses the lat, long values from the SASHELP.ZIPCODE data set. However if you have Zipcodes that do not appear in that set you get a missing values which will screw this up significantly.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 08:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683801#M207150</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-15T08:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Cumulative Distance between longitude/latitude points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683845#M207161</link>
      <description>&lt;P&gt;Shouldn't the two statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if first.state then cum_dist=0;
    cum_dist+geodist(lat,long,lag(lat),lag(long));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;be reversed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise I think the 2nd through last states will start out with the distance between their first zipcode and the last zipcode of the prior state, no?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 03:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683845#M207161</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-15T03:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Cumulative Distance between longitude/latitude points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683907#M207189</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Shouldn't the two statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if first.state then cum_dist=0;
    cum_dist+geodist(lat,long,lag(lat),lag(long));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;be reversed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise I think the 2nd through last states will start out with the distance between their first zipcode and the last zipcode of the prior state, no?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Correct! Good catch!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 10:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Cumulative-Distance-between-longitude-latitude-points/m-p/683907#M207189</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-15T10:26:05Z</dc:date>
    </item>
  </channel>
</rss>

