<?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 How do I calculate quarterly averages using selected observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346440#M79900</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a fairly new SAS user, so forgive me if the solution is easy. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which contains longitudinal data over several years, with multiple observations for each ID. I've coded in what quarter of the year the observation took place. It looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Date Variable Quarter&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;103 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;91 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;90 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx 98 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;97 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;80 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;75 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;70 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to take the highest value of each quarter per subject and calculate their average. Thus, for B it would be [(98+97+75+70)/4)] - the 80 in quarter two should not be calculated). As you can see for A, the preferred value would be [(103+90)/2].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I had thought was to create a multitude of datasets bringing in&amp;nbsp;the highest value for each quarter, then merge them together to do the calculation, but I am sure there is an easier way to do it. How would you do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
    <pubDate>Sat, 01 Apr 2017 22:53:08 GMT</pubDate>
    <dc:creator>tbeaty2</dc:creator>
    <dc:date>2017-04-01T22:53:08Z</dc:date>
    <item>
      <title>How do I calculate quarterly averages using selected observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346440#M79900</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a fairly new SAS user, so forgive me if the solution is easy. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which contains longitudinal data over several years, with multiple observations for each ID. I've coded in what quarter of the year the observation took place. It looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Date Variable Quarter&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;103 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;91 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A &amp;nbsp;xxxx &amp;nbsp;90 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx 98 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;97 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;80 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;75 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;B &amp;nbsp;xxxx &amp;nbsp;70 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to take the highest value of each quarter per subject and calculate their average. Thus, for B it would be [(98+97+75+70)/4)] - the 80 in quarter two should not be calculated). As you can see for A, the preferred value would be [(103+90)/2].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I had thought was to create a multitude of datasets bringing in&amp;nbsp;the highest value for each quarter, then merge them together to do the calculation, but I am sure there is an easier way to do it. How would you do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2017 22:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346440#M79900</guid>
      <dc:creator>tbeaty2</dc:creator>
      <dc:date>2017-04-01T22:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate quarterly averages using selected observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346443#M79901</link>
      <description>&lt;P&gt;Sort with NODUPKEY option, then use PROC MEANS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sort data= have; by Id qtr descending variable;&lt;/P&gt;
&lt;P&gt;proc sort data=have out = unique NODUPKEY; by ID QTR; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2017 22:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346443#M79901</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-01T22:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate quarterly averages using selected observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346468#M79914</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Date $ Variable Quarter;
cards;
A  xxxx  103        1
A  xxxx  91          1
A  xxxx  90          3
B  xxxx 98           1
B  xxxx  97          2
B  xxxx  80          2
B  xxxx  75          3
B  xxxx  70          4
;
run;
proc sql;
create table want as
select id,mean(v) as mean
 from
 (select id,quarter,max(variable) as v from have group by id,quarter)
   group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Apr 2017 02:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346468#M79914</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-02T02:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate quarterly averages using selected observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346586#M79944</link>
      <description>&lt;P&gt;Thank you. both!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 07:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-calculate-quarterly-averages-using-selected/m-p/346586#M79944</guid>
      <dc:creator>tbeaty2</dc:creator>
      <dc:date>2017-04-03T07:05:31Z</dc:date>
    </item>
  </channel>
</rss>

