<?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: Using Max Function inside a DO loop to find the max of each variable in an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312767#M270766</link>
    <description>&lt;P&gt;Here an approach which dynamically determines the variables for the array based on a variable naming pattern.&lt;/P&gt;
&lt;P&gt;It then also determines the variables in the array where the max value over the whole data set is 99 and then only loops over these variables to set 99 to missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var1 var2 var3;
datalines;
23   12   133
94   45   99
99   32   54
;
run;

/* dynamically determine variables for array and number of selected variables */
proc sql noprint;
  select 
    name , count(*)
      into :var_list separated by ' ', :n_vars          
  from dictionary.columns
  where libname='WORK' and memname='HAVE' and upcase(name) like 'VAR%'
  ;
quit;
%let n_vars=%left(&amp;amp;n_vars);
%put &amp;amp;=var_list;
%put &amp;amp;=n_vars;
options symbolgen;

/* determine columns where max value is 99 */
%let elem_99=0;
data _null_;
  set have end=last;
  array in_vars {&amp;amp;n_vars}  &amp;amp;var_list;
  array max_vals {&amp;amp;n_vars} 8 _temporary_;

  do _i=1 to dim(in_vars);
    max_vals{_i}=max(max_vals{_i}, in_vars{_i});
  end;
  
  if last then
    do;
      /* determine columns where max val is 99 */
      length _elements $ 1000;
      do _i=1 to dim(max_vals);
        if max_vals{_i}=99 then _elements=catx(',',_elements,_i);
      end;
      if not missing(_elements) then call symputx('elem_99',_elements);
    end;
run;

%put &amp;amp;=elem_99;


data want(drop=_:);
  set have;
  array in_vars {&amp;amp;n_vars}  &amp;amp;var_list;
  /* only loop over variables where max val is 99 */
  if "&amp;amp;elem_99" ne "0" then
  do;
    do _i=&amp;amp;elem_99;
      if in_vars{_i}=99 then call missing(in_vars{_i});
    end;
  end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Nov 2016 02:53:03 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-11-19T02:53:03Z</dc:date>
    <item>
      <title>Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312637#M270754</link>
      <description>&lt;P&gt;I have a set of variables in a macro and extracted the data for those variables from the main dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to select each variable and check for max values in that variables and set it as null.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created an array and am trying to used do loop to check for max values for each variable in an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But i am not able to use the max function inside an array. It says undeclared array referenced:max&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do i do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;set libname.maindataset (KEEP=ID &amp;amp;variables);&lt;/P&gt;
&lt;P&gt;array var &amp;amp;variables;&lt;BR /&gt;do i=1 to dim(var);&lt;BR /&gt; if max(var[i]) = 99 then do;&lt;BR /&gt; max(var[i])=.&amp;nbsp;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312637#M270754</guid>
      <dc:creator>mrajendranvasanthi</dc:creator>
      <dc:date>2016-11-18T15:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312641#M270755</link>
      <description>&lt;P&gt;I think that you really need to provide a small example of data and what you are trying to get for output.&lt;/P&gt;
&lt;P&gt;Since any variable only has one "maximum" per observation and data step basically processes a single observation at a time what you claim to be attempting is not quite obvious to mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MAX as a function requires at least 2 arguments. I suspect that you have errors in your log. When you use max(var[i])=.&amp;nbsp;; then you have created variable as the max function can not be used in that fashion and since that variable has () it is treated as an array reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to find the maximum value of all of the variables with in an array you can use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; TempMax =&amp;nbsp;max(of var(*)) ;&lt;/P&gt;
&lt;P&gt;where Var is the array name.&lt;/P&gt;
&lt;P&gt;You can then find which of those variables with the WHICHN function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; PositionInArray = whichn(TempMax, of var(*));&lt;/P&gt;
&lt;P&gt;If you &lt;STRONG&gt;know&lt;/STRONG&gt; the value that you are searching for&amp;nbsp; such as 99 that could take the place of TempMax as the value to look for.&lt;/P&gt;
&lt;P&gt;And set that value to missing with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Var[PositionInArray] = . ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are replacing multiple values you will need some additional logic.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312641#M270755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-18T15:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312644#M270756</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;23&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;99&lt;/TD&gt;
&lt;TD align="right"&gt;45&lt;/TD&gt;
&lt;TD align="right"&gt;133&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is how my data looks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes i am looking for only 99 in each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to set 99 in var1 as .(NULL)&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312644#M270756</guid>
      <dc:creator>mrajendranvasanthi</dc:creator>
      <dc:date>2016-11-18T15:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312647#M270757</link>
      <description>&lt;P&gt;Per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;post some example test data (in the form of a datastep) and what the output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also break you logic down into steps:&lt;/P&gt;
&lt;P&gt;1) find max values (proc means, proc sql etc. all can do this)&lt;/P&gt;
&lt;P&gt;2) merge max values onto the data&lt;/P&gt;
&lt;P&gt;3) if value=max value then set it to what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312647#M270757</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-18T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312648#M270758</link>
      <description>&lt;P&gt;Then:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array var{3};
  do over var;
    if var=99 then var=.;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312648#M270758</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-18T15:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312659#M270759</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@mrajendranvasanthi wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="192" style="width: 144pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="3" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="width: 48pt; height: 15pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;23&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;99&lt;/TD&gt;
&lt;TD align="right"&gt;45&lt;/TD&gt;
&lt;TD align="right"&gt;133&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is how my data looks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes i am looking for only 99 in each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to set 99 in var1 as .(NULL)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does the entire output look like. Is the 133 supposed to be null for Var3? The 45 for Var2?&lt;/P&gt;
&lt;P&gt;It could possibly be a better example if the maximum values of the 3 variable do not all appear on the same row and then show what the result is supposed to look like for that set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if your existing data were to be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var1 var 2 var3;
datalines;
23   12   133
94   45   99
99   32   54
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the desired result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could replace the values with . in the example code I just posted to show us.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 16:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312659#M270759</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-18T16:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312669#M270760</link>
      <description>&lt;P&gt;Sorry&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No. if the maximum value of each column&amp;nbsp;is 99 then that 99 should be set to null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this table, it should look like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;23&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/TD&gt;
&lt;TD align="right"&gt;45&lt;/TD&gt;
&lt;TD align="right"&gt;133&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only the the cell in var 1 with value 99 should be set to null. But in var3 99 is not the max value. so it should be good.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if you have any more questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 16:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312669#M270760</guid>
      <dc:creator>mrajendranvasanthi</dc:creator>
      <dc:date>2016-11-18T16:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312671#M270761</link>
      <description>&lt;P&gt;Show what the results for Var2 and Var3 should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only wanted to look at Var1 why bother with an array?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that the desired result (which you have still not provided for the entire data set) for the example I posted would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want ;
  input var1 var 2 var3;
datalines;
23   12   .
94   .   99
.   32   54
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is going to be a somewhat more complicated problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 16:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312671#M270761</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-18T16:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312673#M270762</link>
      <description>&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;23&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/TD&gt;
&lt;TD align="right"&gt;45&lt;/TD&gt;
&lt;TD align="right"&gt;133&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this will be the desired result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need an array because i wanted the code to check for maximum value 99 in each variable even when new variables are added in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if i wanted to check for just for one specific variable i understand it can be done with normal if statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But here the name of the variables might change and new variables can be added into the dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im trying to make it dynamic&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 16:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312673#M270762</guid>
      <dc:creator>mrajendranvasanthi</dc:creator>
      <dc:date>2016-11-18T16:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312702#M270763</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array vars(*) &amp;amp;variables;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if max(of vars(*)) &amp;gt; 99 and whichn(99, of vars(*))&amp;gt;0 then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Do I=1 to dim(vars);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If vars(I) = 99 then call missing(vars(I));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; End;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 18:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312702#M270763</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-18T18:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312706#M270764</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@mrajendranvasanthi wrote:&lt;BR /&gt;
&lt;TABLE width="192" style="width: 144pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="3" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="width: 48pt; height: 15pt;"&gt;var1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;var3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;23&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="height: 15pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/TD&gt;
&lt;TD align="right"&gt;45&lt;/TD&gt;
&lt;TD align="right"&gt;133&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this will be the desired result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need an array because i wanted the code to check for maximum value 99 in each variable even when new variables are added in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So why is the value 99 in VAR3 &lt;STRONG&gt;not set to missing in your example?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 18:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312706#M270764</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-18T18:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312716#M270765</link>
      <description>&lt;P&gt;Is this what you need??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; var1 var2 var3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;23 12 133&lt;/P&gt;
&lt;P&gt;94 45 99&lt;/P&gt;
&lt;P&gt;99 32 54&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;means&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;data&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;=have &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;noprint&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;var&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; var1 var2 var3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;out&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;=stats(drop=_type_ _freq_) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;max&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;=max1 max2 max3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; _n_ = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; stats;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;array&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; m {&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;} max1-max3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;array&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; v {&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;} var1-var3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; i = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;to&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; m{i} = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;99&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; and v{i} = m{i} &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; v{i} = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;keep&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; var1-var3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312716#M270765</guid>
      <dc:creator>Tommywhosc</dc:creator>
      <dc:date>2016-11-18T20:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using Max Function inside a DO loop to find the max of each variable in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312767#M270766</link>
      <description>&lt;P&gt;Here an approach which dynamically determines the variables for the array based on a variable naming pattern.&lt;/P&gt;
&lt;P&gt;It then also determines the variables in the array where the max value over the whole data set is 99 and then only loops over these variables to set 99 to missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var1 var2 var3;
datalines;
23   12   133
94   45   99
99   32   54
;
run;

/* dynamically determine variables for array and number of selected variables */
proc sql noprint;
  select 
    name , count(*)
      into :var_list separated by ' ', :n_vars          
  from dictionary.columns
  where libname='WORK' and memname='HAVE' and upcase(name) like 'VAR%'
  ;
quit;
%let n_vars=%left(&amp;amp;n_vars);
%put &amp;amp;=var_list;
%put &amp;amp;=n_vars;
options symbolgen;

/* determine columns where max value is 99 */
%let elem_99=0;
data _null_;
  set have end=last;
  array in_vars {&amp;amp;n_vars}  &amp;amp;var_list;
  array max_vals {&amp;amp;n_vars} 8 _temporary_;

  do _i=1 to dim(in_vars);
    max_vals{_i}=max(max_vals{_i}, in_vars{_i});
  end;
  
  if last then
    do;
      /* determine columns where max val is 99 */
      length _elements $ 1000;
      do _i=1 to dim(max_vals);
        if max_vals{_i}=99 then _elements=catx(',',_elements,_i);
      end;
      if not missing(_elements) then call symputx('elem_99',_elements);
    end;
run;

%put &amp;amp;=elem_99;


data want(drop=_:);
  set have;
  array in_vars {&amp;amp;n_vars}  &amp;amp;var_list;
  /* only loop over variables where max val is 99 */
  if "&amp;amp;elem_99" ne "0" then
  do;
    do _i=&amp;amp;elem_99;
      if in_vars{_i}=99 then call missing(in_vars{_i});
    end;
  end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 02:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Max-Function-inside-a-DO-loop-to-find-the-max-of-each/m-p/312767#M270766</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-19T02:53:03Z</dc:date>
    </item>
  </channel>
</rss>

