<?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: analysing observations within an observation group, pref. proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265501#M269284</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21847"&gt;@metallon﻿&lt;/a&gt;: Now you've got three solutions producing three different results. A good example of why it makes sense to provide not only sample data, but also sample output.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2016 18:33:20 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-04-21T18:33:20Z</dc:date>
    <item>
      <title>analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265413#M269279</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;BR /&gt;&lt;BR /&gt;I cant get my head around it. I need to&lt;BR /&gt;mark the older animal within an animal-group with a higher Size as 'x' but in case the &lt;BR /&gt;younger animal has a higher Size value with a 'y'&lt;BR /&gt;&lt;BR /&gt;Animal Age Size&lt;BR /&gt;1&amp;nbsp;&amp;nbsp; &amp;nbsp;13&amp;nbsp;&amp;nbsp; &amp;nbsp;18&lt;BR /&gt;1&amp;nbsp;&amp;nbsp; &amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;BR /&gt;2&amp;nbsp;&amp;nbsp; &amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17&lt;BR /&gt;2&amp;nbsp;&amp;nbsp; &amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 18&lt;BR /&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17&lt;BR /&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; 3&amp;nbsp;&amp;nbsp; &amp;nbsp;25&lt;BR /&gt;&lt;BR /&gt;Any ideas? Preferable using proc sql.&lt;BR /&gt;&lt;BR /&gt;I think in Oracle this would work with partitioning the data set.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 13:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265413#M269279</guid>
      <dc:creator>metallon</dc:creator>
      <dc:date>2016-04-21T13:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265416#M269280</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21847"&gt;@metallon﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should be a start:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Animal Age Size;
cards;
1 13 18
1 7 20
2 6 17
2 2 18
3 5 17
3 3 15
;

proc sql;
select a.*, case when a.size&amp;gt;b.size&amp;gt;. then 'x'
                 when a.size&amp;lt;b.size   then 'y'
            end as mark
from have a left join have b
on a.animal=b.animal &amp;amp; a.age&amp;gt;b.age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that I've&amp;nbsp;modified the last Size value to let one 'x' appear.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 13:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265416#M269280</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-21T13:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265422#M269281</link>
      <description>&lt;P&gt;Its a basic sort and by group? &amp;nbsp;Not sure what the complication is on this &amp;nbsp;- you could include it in any other computational block also. &amp;nbsp;Other options include merging/joining.&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
  by animal age size;
run;
data have;
  set have;
  by animal;
  if first.animal then size_result="y";
  else size_result="x";
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 14:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265422#M269281</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-21T14:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265476#M269282</link>
      <description>&lt;P&gt;Partitions are not supported in SAS SQL - the equivalent is usually using a BY group within a data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BY group processing is incredibly powerful and worth learning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001283274.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001283274.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 17:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265476#M269282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-21T17:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265481#M269283</link>
      <description>&lt;P&gt;This is how I translate your requirements into a SAS/SQL query (I added a case where the older animal was also the largest) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data animals;
input AnimalGroup Age Size;
datalines;
1    13    18
1     7      20
2     6      17
2     2      18
3     5      17
3     3    25
4     10   10
4     8    8
;

proc sql;
select 
    *,
    case 
        when age = max(age) and size=max(size) then "x"
        when size = max(size) then "y"
        else " "
        end as maxCode
from animals
group by animalGroup
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 17:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265481#M269283</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-21T17:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: analysing observations within an observation group, pref. proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265501#M269284</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21847"&gt;@metallon﻿&lt;/a&gt;: Now you've got three solutions producing three different results. A good example of why it makes sense to provide not only sample data, but also sample output.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 18:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/analysing-observations-within-an-observation-group-pref-proc-sql/m-p/265501#M269284</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-21T18:33:20Z</dc:date>
    </item>
  </channel>
</rss>

