<?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: How do I pull max of multiple columns in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923442#M363544</link>
    <description>&lt;P&gt;This is not a loop. It is PROC SUMMARY or PROC MEANS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have max;
    var gpa no_of_cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Apr 2024 16:54:39 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-04-08T16:54:39Z</dc:date>
    <item>
      <title>How do I pull max of multiple columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923439#M363543</link>
      <description>&lt;P&gt;I want to loop through all numerical variables and find the max. I would like the results below. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gpa&amp;nbsp; &amp;nbsp; &amp;nbsp;no of cars&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results I want&lt;/P&gt;&lt;P&gt;gpa&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no of cars&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 16:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923439#M363543</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-04-08T16:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pull max of multiple columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923442#M363544</link>
      <description>&lt;P&gt;This is not a loop. It is PROC SUMMARY or PROC MEANS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have max;
    var gpa no_of_cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2024 16:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923442#M363544</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-08T16:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pull max of multiple columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923448#M363545</link>
      <description>&lt;P&gt;For even greater simplicity, you can omit the VAR statement in Paige Miller's PROC MEANS step, as the procedure will then analyze all numeric variables in the input dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 17:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923448#M363545</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-04-08T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pull max of multiple columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923454#M363550</link>
      <description>&lt;P&gt;Paige's example will work just fine. Here's a couple more (I added a couple of records on my own):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input gpa cars;
datalines;
17 4
3 1
7 3
4 1
18 1
5 2
;
run;

** Long and unnecessarily convoluted;
data want1;
set have end=lastrow;

retain gpa_max cars_max; 

if _N_ = 1 then do; /* if 1st record in HAVE ... */
 gpa_max = gpa; /* set GPA_MAX and CARS_MAX to values of GPA &amp;amp; CARS */
 cars_max = cars;
end;

/* if it's not the 1st record .... */
else do;
	if gpa &amp;gt; gpa_max then gpa_max = gpa;
	if cars &amp;gt; cars_max then cars_max = cars;
end;

if lastrow; /* Output if last record in file */

keep gpa_max cars_max;
run;

** Simpler and get the same result;
proc sql;
create table want2 as select
max(gpa) as gpa_max,
max(cars) as cars_max
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2024 18:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923454#M363550</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2024-04-08T18:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pull max of multiple columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923486#M363556</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For even greater simplicity, you can omit the VAR statement in Paige Miller's PROC MEANS step, as the procedure will then analyze all numeric variables in the input dataset.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which may or may not be a good thing to do, if there are hundreds of variables and you only want the max of two of the variables, the VAR statement should be used.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 20:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pull-max-of-multiple-columns-in-SAS/m-p/923486#M363556</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-08T20:01:13Z</dc:date>
    </item>
  </channel>
</rss>

