<?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: Summing and counting based on a parameter difference in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256604#M49197</link>
    <description>Unfortunately I am using Internet Explorer and code posted with braces as the start { does not render properly from this forum. And since your example did not have a variable hdist_i I couldn't tell what impact that had on the problem.</description>
    <pubDate>Mon, 14 Mar 2016 17:33:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-03-14T17:33:52Z</dc:date>
    <item>
      <title>Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256556#M49173</link>
      <description>&lt;P&gt;I want to find avg latitude and longitude of as set of coordinates based on the distance they are from each other. Consider the following example set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
     input lat long lat1 long1 date dt hdist;
     format date dt date9.;
     datalines;
     55.173874 -118.86073 55.173763 -118.85976 20222 20230 0.062882
     55.173786 -118.85968 55.173763 -118.85979 20223 20234 0.007439
     55.173702 -118.85984 55.173775 -118.85979 20225 20235 0.008716
     55.173775 -118.85976 54.685486 -118.77554 20300 20314 54.561229
     55.173763 -118.85976 54.685551 -118.77554 20301 20315 54.552708
     ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I haven't figured out much SAS cdoe to achieve the results. Here is some psuedo code I have thought up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if abs(hdist_i - hdist_{i+1}) &amp;lt; 5 then sum(lat) and sum(lat1) and sum(long) and sum(long1) and cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I would sum lat, long, lat1, long1 for lines 1-3 and have a cnt of 3 and sum lat, long, lat1, long1 for lines 4-5 and have a cnt of 2 so I can take the sums and divide by their respective counts to obtain the average.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From that data, I want to return:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;avg(lat) avg(long) avg(lat1) avg(long1) 20222 20235 for rows 1-3
avg(lat) avg(long) avg(lat1) avg(long1) 20300 20315 for rows 4-5&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 14:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256556#M49173</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-14T14:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256560#M49176</link>
      <description>&lt;P&gt;It sounds like you want to have a classification variable (distance) and then use Proc means or proc summary on the remaining variables to get a mean.&lt;/P&gt;
&lt;P&gt;Easiest might be to create a custom format to group your distance variable into your desired groups. You don't provide a lot of example but something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value DistGroup&lt;/P&gt;
&lt;P&gt;0.005 - 0.07 = 'Group 1'&lt;/P&gt;
&lt;P&gt;54.5 -54.6&amp;nbsp;&amp;nbsp; = 'Group 2'&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; class hdist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format hdist DistGroup.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var lat long lat1 long1 dt date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out= want mean( lat long lat1 long1&amp;nbsp;)=&amp;nbsp; &amp;nbsp;min(date)=&amp;nbsp;&amp;nbsp; max(dt)= ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;guessing on the min and max for the date variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 14:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256560#M49176</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-14T14:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256561#M49177</link>
      <description>&lt;P&gt;Setting groups would be impossible for this set of data. I just pulled out a quick example but we are talking about 100million rows. Also, I would rather have this in a table then a proc means output.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 14:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256561#M49177</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-14T14:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256573#M49183</link>
      <description>&lt;P&gt;So, what are the actual rules for which records are used to calculate a mean? You did not provide any rules just an abitrary first 3 rows and second 2 rows.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 15:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256573#M49183</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-14T15:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256578#M49186</link>
      <description>I did. I said if the absolute value of ith hdist - ith +1 hdist is less than 5</description>
      <pubDate>Mon, 14 Mar 2016 15:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256578#M49186</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-14T15:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256588#M49190</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72834"&gt;@dwsmith﻿&lt;/a&gt; Please recall that you're asking from free help for volunteers. If you review the code suggested, you'll notice that it also produces a dataset called, ironically, WANT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the proc format to categorize the distance into less than 5 or higher than 5.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value DistGroup
0 - 5 = 'Group 1'
5 - high  = 'Group 2'
other = 'CHECKME'
;
 
proc means data=test nway noprint;
   class hdist;
   format hdist DistGroup.;
   var lat long lat1 long1 dt date;
   output out= want mean( lat long lat1 long1 )=   min(date)=   max(dt)= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this doesn't work please post your code, log and explain what is not working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 16:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256588#M49190</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-14T16:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summing and counting based on a parameter difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256604#M49197</link>
      <description>Unfortunately I am using Internet Explorer and code posted with braces as the start { does not render properly from this forum. And since your example did not have a variable hdist_i I couldn't tell what impact that had on the problem.</description>
      <pubDate>Mon, 14 Mar 2016 17:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-and-counting-based-on-a-parameter-difference/m-p/256604#M49197</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-14T17:33:52Z</dc:date>
    </item>
  </channel>
</rss>

