<?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: Multi-Dimensional Array- Checking for match and take the minimum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685362#M207852</link>
    <description>&lt;P&gt;Here is a solution without arrays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set k;
  if not missing(check1) then do;
    pos=whichn(check1,of a1_1--a3_5);
    if pos then select(int(pos/5));
      when(0) min1=min(of a1_:);
      when(1) min1=min(of a2_:);
      when(2) min1=min(of a3_:);
      otherwise;
      end;
    end;
  if not missing(check2) then do;
    pos=whichn(check2,of a1_1--a3_5);
    if pos then select(int(pos/5));
      when(0) min2=min(of a1_:);
      when(1) min2=min(of a2_:);
      when(2) min2=min(of a3_:);
      otherwise;
      end;
    end;  
  drop pos;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have more columns, and/or your variables are not ordered on the dataset so that you can use "of a1_1--a3_5", you can do it with a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getmin(check_no,rows=3,columns=5);
%local rowvars i;
%do i=1 %to &amp;amp;columns;
  %let rowvars=&amp;amp;rowvars a&amp;amp;i._:;
  %end;
  if not missing(check&amp;amp;check_no) then do;
    pos=whichn(check&amp;amp;check_no,of &amp;amp;rowvars);
    if pos then select(int(pos/&amp;amp;columns));
      %do i=1 %to &amp;amp;rows;
        when(%eval(&amp;amp;i-1)) min&amp;amp;check_no=min(of a&amp;amp;i._:);
        %end;
      otherwise;
      end;
    end;
%mend;

options mprint;   
data want;
  set k;
  %getmin(1);
  %getmin(2);
  drop pos;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 21 Sep 2020 10:49:21 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-09-21T10:49:21Z</dc:date>
    <item>
      <title>Multi-Dimensional Array- Checking for match and take the minimum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685355#M207849</link>
      <description>&lt;P&gt;I would like to check where a number is located in a multi-dimensional array.&amp;nbsp; Then, I would like to take the minimum of the entire column for that particular row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have the following data sets. This is a 3-dminesional with 3 rows and 5 columns.&amp;nbsp;&lt;/P&gt;&lt;P&gt;array temp{3,5}&amp;nbsp; a1_1-a1_5&amp;nbsp; a2_1-a2_5 a3_1-a3_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the first observation, Check1= 111 is located at temp{2,3}.&amp;nbsp;&amp;nbsp;For non-missing values, I would like to take the&amp;nbsp;minimum.&amp;nbsp; So, min(a2_1-a2_5)=1.&lt;/P&gt;&lt;P&gt;In the second observation, Check1=222 is located at temp{2,4} and min(a2_1-a2_5)=1.&amp;nbsp; Check2=223 is located at temp{3,2} and min(a3_1-a3_5)=3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; k;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; check1 check2 a1_1 -a1_5 a2_1-a2_5 a3_1-a3_5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;111 . 12 122 133 . . 1 11 111 13 . 777 2 . . .&lt;/P&gt;&lt;P&gt;222 223 5 555 232 . . 1 111 123 222 224 11 223 3 . .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 09:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685355#M207849</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2020-09-21T09:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-Dimensional Array- Checking for match and take the minimum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685362#M207852</link>
      <description>&lt;P&gt;Here is a solution without arrays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set k;
  if not missing(check1) then do;
    pos=whichn(check1,of a1_1--a3_5);
    if pos then select(int(pos/5));
      when(0) min1=min(of a1_:);
      when(1) min1=min(of a2_:);
      when(2) min1=min(of a3_:);
      otherwise;
      end;
    end;
  if not missing(check2) then do;
    pos=whichn(check2,of a1_1--a3_5);
    if pos then select(int(pos/5));
      when(0) min2=min(of a1_:);
      when(1) min2=min(of a2_:);
      when(2) min2=min(of a3_:);
      otherwise;
      end;
    end;  
  drop pos;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have more columns, and/or your variables are not ordered on the dataset so that you can use "of a1_1--a3_5", you can do it with a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getmin(check_no,rows=3,columns=5);
%local rowvars i;
%do i=1 %to &amp;amp;columns;
  %let rowvars=&amp;amp;rowvars a&amp;amp;i._:;
  %end;
  if not missing(check&amp;amp;check_no) then do;
    pos=whichn(check&amp;amp;check_no,of &amp;amp;rowvars);
    if pos then select(int(pos/&amp;amp;columns));
      %do i=1 %to &amp;amp;rows;
        when(%eval(&amp;amp;i-1)) min&amp;amp;check_no=min(of a&amp;amp;i._:);
        %end;
      otherwise;
      end;
    end;
%mend;

options mprint;   
data want;
  set k;
  %getmin(1);
  %getmin(2);
  drop pos;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Sep 2020 10:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685362#M207852</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-21T10:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-Dimensional Array- Checking for match and take the minimum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685364#M207854</link>
      <description>&lt;P&gt;Presumably, since you are defining a three-dimensional array, you would have at least a small amount of familiarity with them.&amp;nbsp; Are you able to find which element matches the contents of CHECK1?&lt;/P&gt;
&lt;P&gt;The rest of the problem becomes easier if you construct a second array holding the array minimums.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array mins {3} min_row1-min_row3;
if _n_=1 then do _n_=1 to 3;
   min_row1 = min(of a1_1-a1_5);
   min_row2 = min(of a2_1-a2_5);
   min_row3 = min(of a3_1=a3_5);
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then find the element that matches CHECK1, find its row number within the three-dimensional array, and extract the proper element from the MINS array.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 10:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multi-Dimensional-Array-Checking-for-match-and-take-the-minimum/m-p/685364#M207854</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-21T10:54:34Z</dc:date>
    </item>
  </channel>
</rss>

