<?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: Mean calculation based on 2nd data time range? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13189#M1538</link>
    <description>This would have been easier if the time ranges did not overlap. Having no overlaps would have allowed us to utilize various table look-up techniques like formats, hash tables, or arrays.&lt;BR /&gt;
&lt;BR /&gt;
My macro solution is unnecessarily complicated and inefficient. See Joe's or data _null_'s.&lt;BR /&gt;
&lt;BR /&gt;
(my code is little too long for this forum. I have posted the code on sas-l:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=43780" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=43780&lt;/A&gt; )&lt;BR /&gt;
&lt;BR /&gt;
Look at Joe Matise's succinct proc sql solution at:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=44045" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=44045&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Or data _null_'s using the multi-label format:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;F=&amp;amp;S=&amp;amp;P=44173" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;F=&amp;amp;S=&amp;amp;P=44173&lt;/A&gt;</description>
    <pubDate>Thu, 07 Oct 2010 18:17:27 GMT</pubDate>
    <dc:creator>chang_y_chung_hotmail_com</dc:creator>
    <dc:date>2010-10-07T18:17:27Z</dc:date>
    <item>
      <title>Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13185#M1534</link>
      <description>How to do data1 stat  (for example mean) calculation based on data2 time range? &lt;BR /&gt;
&lt;BR /&gt;
Data1&lt;BR /&gt;
&lt;BR /&gt;
time x y&lt;BR /&gt;
11:00 2 3 &lt;BR /&gt;
11:02 7 8&lt;BR /&gt;
11:03 4 5&lt;BR /&gt;
11:07 10 30&lt;BR /&gt;
12:00 30 20&lt;BR /&gt;
12:03 21 4&lt;BR /&gt;
..............&lt;BR /&gt;
&lt;BR /&gt;
Data2&lt;BR /&gt;
TimeStart TimeEnd&lt;BR /&gt;
11:00 11:07&lt;BR /&gt;
11:03 12:00&lt;BR /&gt;
12:00 12:03&lt;BR /&gt;
....................&lt;BR /&gt;
&lt;BR /&gt;
Want to get results&lt;BR /&gt;
TimeStart TimeEnd MeanX meanY&lt;BR /&gt;
11:00 11:07 ? ?&lt;BR /&gt;
11:03 12:00 ? ?&lt;BR /&gt;
12:00 12:03 ? ?&lt;BR /&gt;
............................</description>
      <pubDate>Wed, 06 Oct 2010 19:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13185#M1534</guid>
      <dc:creator>JeffNCSU</dc:creator>
      <dc:date>2010-10-06T19:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13186#M1535</link>
      <description>Have a look at PROC SQL&lt;BR /&gt;
Select starttime, endtime, mean(x) as meanX, mean(y) as meanY&lt;BR /&gt;
from data1 a, data2 b&lt;BR /&gt;
where a.time between starttime and endtime&lt;BR /&gt;
Group by starttime, endtime&lt;BR /&gt;
 &lt;BR /&gt;
Well, something like that......&lt;BR /&gt;
 &lt;BR /&gt;
peterC&lt;BR /&gt;
(not used to SAS-ing on iPhone standing on a crowded commuter train)&lt;BR /&gt;
&lt;BR /&gt;
new defn of unstable code &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
Needed group by&lt;BR /&gt;
and "time" names reversed&lt;BR /&gt;
and a new name for the mean() stat variables&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Thu, 07 Oct 2010 07:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13186#M1535</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-10-07T07:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13187#M1536</link>
      <description>Thanks! PeterC, &lt;BR /&gt;
&lt;BR /&gt;
Could you please give me an example?  I am not familar with Proc SQL.</description>
      <pubDate>Thu, 07 Oct 2010 13:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13187#M1536</guid>
      <dc:creator>JeffNCSU</dc:creator>
      <dc:date>2010-10-07T13:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13188#M1537</link>
      <description>There is much information on the SAS support website, with technical reference, conference papers, and SAS-hosted documentation.  Suggest using the SEARCH facility there or consider a Google advanced search argument, such as:&lt;BR /&gt;
&lt;BR /&gt;
proc sql example site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 07 Oct 2010 14:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13188#M1537</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-07T14:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13189#M1538</link>
      <description>This would have been easier if the time ranges did not overlap. Having no overlaps would have allowed us to utilize various table look-up techniques like formats, hash tables, or arrays.&lt;BR /&gt;
&lt;BR /&gt;
My macro solution is unnecessarily complicated and inefficient. See Joe's or data _null_'s.&lt;BR /&gt;
&lt;BR /&gt;
(my code is little too long for this forum. I have posted the code on sas-l:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=43780" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=43780&lt;/A&gt; )&lt;BR /&gt;
&lt;BR /&gt;
Look at Joe Matise's succinct proc sql solution at:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=44045" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;P=44045&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Or data _null_'s using the multi-label format:&lt;BR /&gt;
&lt;A href="http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;F=&amp;amp;S=&amp;amp;P=44173" target="_blank"&gt;http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1010a&amp;amp;L=sas-l&amp;amp;D=1&amp;amp;O=D&amp;amp;F=&amp;amp;S=&amp;amp;P=44173&lt;/A&gt;</description>
      <pubDate>Thu, 07 Oct 2010 18:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13189#M1538</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-10-07T18:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Mean calculation based on 2nd data time range?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13190#M1539</link>
      <description>JeffNcsu&lt;BR /&gt;
&lt;BR /&gt;
sorry you didn't understand:&lt;BR /&gt;
examples you can find in the manual &lt;BR /&gt;
examples you can find in online-doc&lt;BR /&gt;
&lt;BR /&gt;
what you got with my posting was the sql you need&lt;BR /&gt;
(apart from the top and tail&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
 create table results as&lt;BR /&gt;
&lt;BR /&gt;
Select TimeStart, TimeEnd, mean(x) as meanX, mean(y) as meanY&lt;BR /&gt;
from data1 a, data2 b&lt;BR /&gt;
where a.time between TimeStart and TimeEnd&lt;BR /&gt;
Group by TimeStart, TimeEnd&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
quit ;&lt;BR /&gt;
That produced these work.RESULTS, based on your sample data[pre]+FSVIEW:  WORK.RESULTS (B)-------------------------------+                                                                              &lt;BR /&gt;
| Obs     TimeStart  TimeEnd         meanX         meanY |                                                                              &lt;BR /&gt;
|                                                        |                                                                              &lt;BR /&gt;
|   1         11:00    11:07          5.75          11.5 |                                                                              &lt;BR /&gt;
|   2         11:03    12:00  14.666666667  18.333333333 |                                                                              &lt;BR /&gt;
|   3         12:00    12:03          25.5            12 |                                                                              &lt;BR /&gt;
|                                                        |                                                                              &lt;BR /&gt;
+--------------------------------------------------------+[/pre]since these are the results you seemed to be asking for, it is a bit disappointed you didn't try&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Fri, 08 Oct 2010 11:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mean-calculation-based-on-2nd-data-time-range/m-p/13190#M1539</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-10-08T11:54:40Z</dc:date>
    </item>
  </channel>
</rss>

