<?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: proc sql max function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487889#M127152</link>
    <description>&lt;P&gt;Are you missing having clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as 
select distinct stu_id,  term, score
from table
group by stu_id
having term=max(term)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Aug 2018 18:35:39 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-08-17T18:35:39Z</dc:date>
    <item>
      <title>proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487879#M127150</link>
      <description>&lt;P&gt;So I have 100k+ records. Some students have taken this test several times and have gotten different scores. I'm trying to select the max term and the score that would accompany that&amp;nbsp;latest term for each student.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as 
select distinct stu_id, max(term) as term, score
from table
group by stu_id, score
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if I have this student&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;005G0K2W&amp;nbsp;3&amp;nbsp;400&lt;/P&gt;&lt;P&gt;005G0K2W&amp;nbsp;5&amp;nbsp;235&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is what I end up getting, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;005G0K2W 5&amp;nbsp;400&lt;/P&gt;&lt;P&gt;005G0K2W 5&amp;nbsp;235&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I want this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;005G0K2W 5 235&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit: students don't have to have all terms or be enrolled up to term 5, so some students might only have term 1, some might have terms 2 and 5 or any other combination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;009FX8YG 1&amp;nbsp;111&lt;/P&gt;&lt;P&gt;009FX8YG 4&amp;nbsp;259&lt;/P&gt;&lt;P&gt;010G0K2W&amp;nbsp;3 400&lt;/P&gt;&lt;P&gt;010G0K2W 5&amp;nbsp;235&lt;/P&gt;&lt;P&gt;01WG248D 2&amp;nbsp;369&lt;/P&gt;&lt;P&gt;01WG248D 3&amp;nbsp;326&lt;/P&gt;&lt;P&gt;09FX569H 2 654&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;009FX8YG 4&amp;nbsp;259&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;010G0K2W 5&amp;nbsp;235&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01WG248D 3&amp;nbsp;326&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;09FX569H 2 654&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487879#M127150</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-08-17T18:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487889#M127152</link>
      <description>&lt;P&gt;Are you missing having clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as 
select distinct stu_id,  term, score
from table
group by stu_id
having term=max(term)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487889#M127152</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T18:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487895#M127156</link>
      <description>&lt;P&gt;This will not work...it keeps only the max term overall (5). So terms 1,2,3,4 are&amp;nbsp;now completely gone along with the students that don't have a term 5.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487895#M127156</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-08-17T18:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487896#M127157</link>
      <description>&lt;P&gt;Ok, Can you please provide a better and comprehensive sample of what you HAVE and what you WANT, so that the community can code, test and then post plz&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487896#M127157</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T18:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487899#M127159</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input stu_id $ term score;
cards;
009FX8YG 1 111
009FX8YG 4 259
010G0K2W 3 400
010G0K2W 5 235
01WG248D 2 369
01WG248D 3 326
09FX569H 2 654
;

proc sql;
create table want as
select *
from have
group by stu_id
having term=max(term);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 19:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487899#M127159</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T19:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487901#M127160</link>
      <description>&lt;P&gt;Thank you!! Your previous response was correct as well I just didn't see that group by...thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 19:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-max-function/m-p/487901#M127160</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-08-17T19:05:29Z</dc:date>
    </item>
  </channel>
</rss>

