<?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: Selecting max value from multiple observations in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2057#M126</link>
    <description>&amp;gt; I have the following variables (id and score) and&lt;BR /&gt;
&amp;gt; would like to know how to get the third variable&lt;BR /&gt;
&amp;gt; maxscore:&lt;BR /&gt;
&amp;gt; id  score  maxscore&lt;BR /&gt;
&amp;gt; 1     5       7&lt;BR /&gt;
&amp;gt; 1     7       7&lt;BR /&gt;
&amp;gt; 1     3       7&lt;BR /&gt;
&amp;gt; 2     2       8&lt;BR /&gt;
&amp;gt; 2     1       8&lt;BR /&gt;
&amp;gt; 2     8       8&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What is the code that I'll need to use to get&lt;BR /&gt;
&amp;gt; maxscore to pick the largest value from the&lt;BR /&gt;
&amp;gt; observations for each id?&lt;BR /&gt;
&amp;gt; Thank you for your help!&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You can use either a Proc SQL step or a data step to find a solution. SQL may appear concise but it also preprocesses the data to arrive at the max score for each ID. I have presented only the SQL solution below:&lt;BR /&gt;
&lt;BR /&gt;
data NOmaxscore ;&lt;BR /&gt;
  input id score ;&lt;BR /&gt;
  cards ;&lt;BR /&gt;
1 5&lt;BR /&gt;
1 7&lt;BR /&gt;
1 3&lt;BR /&gt;
2 2&lt;BR /&gt;
2 1&lt;BR /&gt;
2 8&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
  create table WITHmaxscore as&lt;BR /&gt;
    select * , max(score) as maxscore&lt;BR /&gt;
      from NOmaxscore &lt;BR /&gt;
      group by id ;&lt;BR /&gt;
quit ;&lt;BR /&gt;
&lt;BR /&gt;
options nocenter ;&lt;BR /&gt;
proc print ; &lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
And this yields:&lt;BR /&gt;
&lt;BR /&gt;
Obs    id    score    maxscore&lt;BR /&gt;
&lt;BR /&gt;
 1      1      5          7&lt;BR /&gt;
 2      1      3          7&lt;BR /&gt;
 3      1      7          7&lt;BR /&gt;
 4      2      8          8&lt;BR /&gt;
 5      2      1          8&lt;BR /&gt;
 6      2      2          8&lt;BR /&gt;
&lt;BR /&gt;
Venky Chakravarthy</description>
    <pubDate>Wed, 10 Jan 2007 19:34:12 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-01-10T19:34:12Z</dc:date>
    <item>
      <title>Selecting max value from multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2056#M125</link>
      <description>I have the following variables (id and score) and would like to know how to get the third variable maxscore:&lt;BR /&gt;
id  score  maxscore&lt;BR /&gt;
1     5       7&lt;BR /&gt;
1     7       7&lt;BR /&gt;
1     3       7&lt;BR /&gt;
2     2       8&lt;BR /&gt;
2     1       8&lt;BR /&gt;
2     8       8&lt;BR /&gt;
&lt;BR /&gt;
What is the code that I'll need to use to get maxscore to pick the largest value from the observations for each id?&lt;BR /&gt;
Thank you for your help!</description>
      <pubDate>Wed, 10 Jan 2007 18:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2056#M125</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-10T18:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting max value from multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2057#M126</link>
      <description>&amp;gt; I have the following variables (id and score) and&lt;BR /&gt;
&amp;gt; would like to know how to get the third variable&lt;BR /&gt;
&amp;gt; maxscore:&lt;BR /&gt;
&amp;gt; id  score  maxscore&lt;BR /&gt;
&amp;gt; 1     5       7&lt;BR /&gt;
&amp;gt; 1     7       7&lt;BR /&gt;
&amp;gt; 1     3       7&lt;BR /&gt;
&amp;gt; 2     2       8&lt;BR /&gt;
&amp;gt; 2     1       8&lt;BR /&gt;
&amp;gt; 2     8       8&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What is the code that I'll need to use to get&lt;BR /&gt;
&amp;gt; maxscore to pick the largest value from the&lt;BR /&gt;
&amp;gt; observations for each id?&lt;BR /&gt;
&amp;gt; Thank you for your help!&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You can use either a Proc SQL step or a data step to find a solution. SQL may appear concise but it also preprocesses the data to arrive at the max score for each ID. I have presented only the SQL solution below:&lt;BR /&gt;
&lt;BR /&gt;
data NOmaxscore ;&lt;BR /&gt;
  input id score ;&lt;BR /&gt;
  cards ;&lt;BR /&gt;
1 5&lt;BR /&gt;
1 7&lt;BR /&gt;
1 3&lt;BR /&gt;
2 2&lt;BR /&gt;
2 1&lt;BR /&gt;
2 8&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
  create table WITHmaxscore as&lt;BR /&gt;
    select * , max(score) as maxscore&lt;BR /&gt;
      from NOmaxscore &lt;BR /&gt;
      group by id ;&lt;BR /&gt;
quit ;&lt;BR /&gt;
&lt;BR /&gt;
options nocenter ;&lt;BR /&gt;
proc print ; &lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
And this yields:&lt;BR /&gt;
&lt;BR /&gt;
Obs    id    score    maxscore&lt;BR /&gt;
&lt;BR /&gt;
 1      1      5          7&lt;BR /&gt;
 2      1      3          7&lt;BR /&gt;
 3      1      7          7&lt;BR /&gt;
 4      2      8          8&lt;BR /&gt;
 5      2      1          8&lt;BR /&gt;
 6      2      2          8&lt;BR /&gt;
&lt;BR /&gt;
Venky Chakravarthy</description>
      <pubDate>Wed, 10 Jan 2007 19:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2057#M126</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-10T19:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting max value from multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2058#M127</link>
      <description>Thank you very much!</description>
      <pubDate>Wed, 10 Jan 2007 20:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Selecting-max-value-from-multiple-observations/m-p/2058#M127</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-10T20:31:56Z</dc:date>
    </item>
  </channel>
</rss>

