<?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: SAS Proc Means for Choosing Max Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789559#M252659</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code should do the trick, but records are not returned in same order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=work.have out=work.want0;
 by record_id ColA descending ColB;
run;

data work.want1;
 set work.want0;
 by record_id ColA descending ColB;
 if first.ColA then output;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jan 2022 18:07:21 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2022-01-11T18:07:21Z</dc:date>
    <item>
      <title>SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789555#M252656</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this dataset, where Col A could have a repeating value (e.g. 990).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.46.46 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67320iACFBB01487394CD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.46.46 PM.png" alt="Screen Shot 2022-01-11 at 12.46.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would like the dataset to look like this (select for highest value of '990' so =3)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.53.05 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67324i2102AA5374904749/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.53.05 PM.png" alt="Screen Shot 2022-01-11 at 12.53.05 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code that I found on SAS communities (and a few other variations of it):&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;data&lt;/SPAN&gt;=sashelp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;class&lt;/SPAN&gt; record_id ColA;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; ColB;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;output&lt;/SPAN&gt; &lt;SPAN class=""&gt;out&lt;/SPAN&gt;=want &lt;SPAN class=""&gt;max&lt;/SPAN&gt;(ColB)=ColB;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;I ended up getting this output where instead of sas giving me the highest value, I got the average of the values of 990. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.51.23 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67325iBEFD396FF438F736/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.51.23 PM.png" alt="Screen Shot 2022-01-11 at 12.51.23 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class=""&gt; &lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;How do I fix it so that SAS gives me only the highest value for a repeating observation instead of the average?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;Thanks in advance!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 17:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789555#M252656</guid>
      <dc:creator>Zozo1998</dc:creator>
      <dc:date>2022-01-11T17:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789556#M252657</link>
      <description>&lt;P&gt;That's easy&lt;/P&gt;
&lt;P&gt;, but can you provide us with your (sample) data by means of a data step with datalines (cards) statement?&lt;BR /&gt;We cannot code against a picture.&lt;BR /&gt;When pasting your SAS code (the requested data step), use the running man icon in the toolbar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 18:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789556#M252657</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-01-11T18:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789558#M252658</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/345977"&gt;@Zozo1998&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this dataset, where Col A could have a repeating value (e.g. 990).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.46.46 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67320iACFBB01487394CD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.46.46 PM.png" alt="Screen Shot 2022-01-11 at 12.46.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I would like the dataset to look like this (select for highest value of '990' so =3)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.53.05 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67324i2102AA5374904749/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.53.05 PM.png" alt="Screen Shot 2022-01-11 at 12.53.05 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this code that I found on SAS communities (and a few other variations of it):&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&lt;STRONG&gt;means&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;data&lt;/SPAN&gt;=sashelp;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;class&lt;/SPAN&gt; record_id ColA;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; ColB;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;output&lt;/SPAN&gt; &lt;SPAN class=""&gt;out&lt;/SPAN&gt;=want &lt;SPAN class=""&gt;max&lt;/SPAN&gt;(ColB)=ColB;&lt;/P&gt;
&lt;P class=""&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;I ended up getting this output where instead of sas giving me the highest value, I got the average of the values of 990. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-01-11 at 12.51.23 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67325iBEFD396FF438F736/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-01-11 at 12.51.23 PM.png" alt="Screen Shot 2022-01-11 at 12.51.23 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P class=""&gt; &lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;How do I fix it so that SAS gives me only the highest value for a repeating observation instead of the average?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=""&gt;&lt;SPAN class=""&gt;Thanks in advance!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is the format on variable ColB, according to PROC CONTENTS?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 18:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789558#M252658</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-11T18:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789559#M252659</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code should do the trick, but records are not returned in same order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=work.have out=work.want0;
 by record_id ColA descending ColB;
run;

data work.want1;
 set work.want0;
 by record_id ColA descending ColB;
 if first.ColA then output;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 18:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/789559#M252659</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-01-11T18:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/790335#M253021</link>
      <description />
      <pubDate>Sat, 15 Jan 2022 16:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/790335#M253021</guid>
      <dc:creator>Zozo1998</dc:creator>
      <dc:date>2022-01-15T16:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Proc Means for Choosing Max Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/790358#M253036</link>
      <description>&lt;P&gt;Its fine that you have marked the answer as correct, as I'm sure it is correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, there's no reason that PROC MEANS won't give you the correct maximum either ... and so again I conclude that there's something going in your specific data that you haven't told us about (and maybe it is something you aren't even aware of), and again I suspect you have formatted the variable somehow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For anyone else reading along, PROC MEANS ought to do the job properly.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jan 2022 21:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Proc-Means-for-Choosing-Max-Value/m-p/790358#M253036</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-15T21:09:59Z</dc:date>
    </item>
  </channel>
</rss>

