<?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: IF VS Where in Datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700123#M214237</link>
    <description>&lt;P&gt;The Data Step Max Function reads a list of arguments and returns the largest one. So if you have 1 argument, that argument is returnes. Ie Max(age) = Age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is your goal here? Do you really want a single observation in a new data set with the max value for age? Or do you just want to know what max(age) is?&lt;/P&gt;</description>
    <pubDate>Thu, 19 Nov 2020 07:08:46 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-11-19T07:08:46Z</dc:date>
    <item>
      <title>IF VS Where in Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700116#M214233</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*IF vs Where in Datastep using Aggregate Functions*/
data if;
set sashelp.class;
if Max(Age) then output;
run;

data wh;
set sashelp.class;
where Max(Age);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here I got same output ,I want max age in class dataset&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 06:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700116#M214233</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-11-19T06:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF VS Where in Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700118#M214235</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation, here of the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n00bjr4jof59pwn1bfzk9f5i0ujr.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;MAX Function&lt;/A&gt;:&lt;/P&gt;
&lt;H4 class="xisDoc-argument"&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;argument&lt;/EM&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;specifies a numeric constant, variable, or expression. At least one argument is required. &lt;STRONG&gt;If you use only one argument, then the value of that argument is returned&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;(emphasis by me)&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;So in both your examples, the value of age is returned; since all observations in SASHELP.CLASS have a non-missing and non-zero age, the condition will always be true, so all observations are written to the output dataset.&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;If you want to retrieve the maximum of all ages in SASHELP.CLASS, you need to use the &lt;STRONG&gt;SQL summary function&lt;/STRONG&gt; MAX:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select max(age) from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 19 Nov 2020 07:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700118#M214235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-19T07:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: IF VS Where in Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700123#M214237</link>
      <description>&lt;P&gt;The Data Step Max Function reads a list of arguments and returns the largest one. So if you have 1 argument, that argument is returnes. Ie Max(age) = Age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is your goal here? Do you really want a single observation in a new data set with the max value for age? Or do you just want to know what max(age) is?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 07:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700123#M214237</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-19T07:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: IF VS Where in Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700135#M214243</link>
      <description>&lt;P&gt;If you want do get it with data step you can do it with help of DoW-loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
  do until(eof);
    set sashelp.class end=eof;
    max = max(max,Age);
  end;

  do until(end);
    set sashelp.class end=end;
    if max = Age then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I would use SQL for this task:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want2 as
  select * 
  from sashelp.class
  having age = max(age)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 07:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700135#M214243</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-11-19T07:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: IF VS Where in Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700213#M214275</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860" target="_blank" rel="noopener"&gt;Anandkvn&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;Function max() works within single observation.&lt;/P&gt;
&lt;P&gt;If you want get max of a variable across the observations you may use methods suggested by &lt;A class="trigger-hovercard" style="color: #009999;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank"&gt;KurtBremse&lt;/A&gt; and &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763" target="_blank"&gt;yabwon&lt;/A&gt; .&lt;/P&gt;
&lt;P&gt;Another way of getting max(AGE) is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=work.class;
   by descending AGE;
run;

data work.maxage;
   set work.class (obs=1);
   put 'max(AGE)=' AGE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 14:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-VS-Where-in-Datastep/m-p/700213#M214275</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-11-19T14:53:45Z</dc:date>
    </item>
  </channel>
</rss>

