<?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: Find Min and Max of five variables with min above zero for each row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923693#M363643</link>
    <description>&lt;P&gt;You may have to protect against all missing IR values or all zeroes.&amp;nbsp; If so, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have ;
  if n(of IR:)&amp;gt;0 then max=max(of IR:);
  if max=0 then max=.;

  if max&amp;gt;0 then do _r=1 to n(of IR:) until(min&amp;gt;0);
    min=smallest(_r,of IR:);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "do ... UNTIL" using smallest is a way to avoid min=0.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2024 02:16:21 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-04-10T02:16:21Z</dc:date>
    <item>
      <title>Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923523#M363558</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with 6 variables: ID, IR00, IR10, IR20, IR30, IR40.&amp;nbsp; ID is an 8 digit numeric ID.&amp;nbsp; IR00 through IR40 are each continous variable from 0 to 1.&amp;nbsp; I need to find the min and max for each ID across the IR00 to IR40 variables. The min has to be above 0.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found the max using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;MAX_IR = max(of IR00 - IR40) ;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;keep ID IR00 IR10 IR20 IR30 IR40 MAX_IR;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I cannot figure out how to find the min value above zero.&amp;nbsp; Any help would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 02:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923523#M363558</guid>
      <dc:creator>jbird</dc:creator>
      <dc:date>2024-04-09T02:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923531#M363562</link>
      <description>&lt;P&gt;Can't think of anything "shorthand". Below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;
  array vars{*} IR00 - IR40;
  do i=1 to dim(vars);
    if vars[i]&amp;gt;0 then min_ir=min(min_ir,vars[i]);
  end;

  MAX_IR = max(of IR00 - IR40);
  output;
  keep ID IR00 IR10 IR20 IR30 IR40 MAX_IR min_ir;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2024 03:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923531#M363562</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-09T03:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923532#M363563</link>
      <description>&lt;P&gt;Try this. The SMALLEST function ignores missing values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;
  MAX_IR = max(of IR00 - IR40);
  if IR00 = 0 then IR00 = .;
  if IR10 = 0 then IR10 = .;
  if IR20 = 0 then IR20 = .;
  if IR30 = 0 then IR30 = .;
  if IR40 = 0 then IR40 = .;
  MIN_IR = smallest(of IR00 - IR40);
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2024 03:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923532#M363563</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-04-09T03:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923534#M363564</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;Also the min() function skips missings but I believe the real "challenge" is: "The min has to be above 0. "&lt;/P&gt;
&lt;P&gt;if IR00 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;lt;&lt;/FONT&gt;&lt;/STRONG&gt;= 0 then IR00 = .;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 03:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923534#M363564</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-09T03:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923552#M363575</link>
      <description>&lt;P&gt;With SAS Arrays?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
  call streaminit(42);
  do id = 1 to 1e2;
    array ir IR00 IR10 IR20 IR30 IR40;
    do over IR;
      IR = rand("integer",0,9)/10;
    end;
  output;
  end;
run;

data new;
  set old;

  array IR IR:;
  do over IR;
               MAX_IR = max(MAX_IR,IR);
    if IR then MIN_IR = min(MIN_IR,IR);
  end;

  keep ID IR: M:; 
run; 
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Just for fun&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;

  array IR IR:;
  do over IR;
    MAX_IR = MAX_IR&amp;lt;&amp;gt;IR;
    MIN_IR = min(MIN_IR,IR+(0=IR));
  end;

  keep ID IR: M:; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2024 09:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923552#M363575</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-09T09:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923555#M363577</link>
      <description>&lt;P&gt;One more just for fun:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;

  array IR IR:; /* make 0 to . */
  do over IR;
    IR = ifn(IR,IR,.);
  end;
  MAX_IR = max(of IR[*]);
  MIN_IR = min(of IR[*]);

  set old;

  keep ID IR: M:; 
run; 
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2024 10:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923555#M363577</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-09T10:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Find Min and Max of five variables with min above zero for each row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923693#M363643</link>
      <description>&lt;P&gt;You may have to protect against all missing IR values or all zeroes.&amp;nbsp; If so, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have ;
  if n(of IR:)&amp;gt;0 then max=max(of IR:);
  if max=0 then max=.;

  if max&amp;gt;0 then do _r=1 to n(of IR:) until(min&amp;gt;0);
    min=smallest(_r,of IR:);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "do ... UNTIL" using smallest is a way to avoid min=0.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 02:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Min-and-Max-of-five-variables-with-min-above-zero-for-each/m-p/923693#M363643</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-04-10T02:16:21Z</dc:date>
    </item>
  </channel>
</rss>

