<?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 to find min variable when there are two or more value exist? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594433#M170776</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You can nest DO loops over implicit arrays all you want if you define the arrays with different indices, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                                                                                                                                                                                                                   
  array ii (i) i1-i3 (1 2 3) ;                                                                                                                                                                                                                                  
  array jj (j) j1-j2 (4 5) ;                                                                                                                                                                                                                                    
  do over ii ;                                                                                                                                                                                                                                                  
    do over jj ;                                                                                                                                                                                                                                                
      put ii= jj= ;                                                                                                                                                                                                                                             
    end ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
run ;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;i1=1 j1=4
i1=1 j2=5
i2=2 j1=4
i2=2 j2=5
i3=3 j1=4
i3=3 j2=5
&lt;/PRE&gt;
&lt;P&gt;Moreover, you can create an implicit array that contains other implicit arrays as its elements - the ability woefully absent from explicitly subscripted arrays. SAS User's Guide: Basics, Version 5 Edition, pages 48-49 (45-49 about the implicit arrays in general). The functionality, despite being as of 1985, still works like a champ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2019 08:43:17 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-10-07T08:43:17Z</dc:date>
    <item>
      <title>How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594295#M170713</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG 7.1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My purpose is find to minimum value of FEE_A - ...&amp;nbsp;-&amp;nbsp;FEE_D columns and print to column name as 'ASSIGNMENT'. If two or more minimum value is exist this time i want to print column name have maximum value of SCORE_A - ... SCORE_D columns.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Ekran Resmi 2019-10-05 22.43.33.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32989iC121DE5F40D17816/image-size/large?v=v2&amp;amp;px=999" role="button" title="Ekran Resmi 2019-10-05 22.43.33.png" alt="Ekran Resmi 2019-10-05 22.43.33.png" /&gt;&lt;/span&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to add 'Assignment' column.&lt;/P&gt;&lt;P&gt;On first, second and third row; there are only one minimum value of Fee_A - ... - Fee_D.&lt;/P&gt;&lt;P&gt;On fourth and fifth row; there are equal minimum value of fee_.. columns (eg. for fourth row; FEE_B = FEE_D = 2) But SCORE_D &amp;gt; SCORE_B (100&amp;gt;90) so value of ASSIGNMENT column is D.&lt;/P&gt;&lt;P&gt;On sixth row; there are two minimum value (FEE_C = FEE_D = 2) and values of SCORE_C and SCORE_D are equal. (60) For this case it doesn't matter what print 'C' or 'D' value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For insert my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_1;                    
input 
ID SCORE_A SCORE_B SCORE_C SCORE_D
FEE_A FEE_B FEE_C FEE_D;
 
datalines;  
111111  70  85  50    60    2  4  3  8
222222  80  65  80    70    9  4  5  1
333333  60  70  70    100   5  3  5  4
444444  60  90  100   100   7  2  3  2
555555  40  70  80    50    4  1  5  1
666666  75  80  60    60    9  3  2  2
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to write code below, but i could not. In addition, actually I have approximately 100 columns both 'score_...' and&amp;nbsp;'fee_...' so I have to use macro and array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.table_2;
set work.table_1;

array all_fee [*] &amp;amp;fee.;  /*i create this macro before*/

counter = 0;
do i=1 to dim(all_fee);
if all_fee{i} = min(of all_fee(*)) then counter = counter + 1; else counter = counter;
end;

length multi_min $ 500;
length ASSIGNMENT $ 500;

do i=1 to dim(all_fee);

 if counter = 0 then assignment = '' ; end;
 else if counter = 1 then do;
        if all_fee{i} = min(of all_fee(*)) then do;
        assignment = substr((vname(all_fee{i})), 5, (length((vname(all_fee{i})))-4));,
        end;
       end;
 else if counter &amp;gt; 1 then do;
        if all_fee{i} = min(of all_fee(*)) then do;
        multi_min = catx(' ', multi_min, (substr((vname(all_fee{i})), 5, (length((vname(all_fee{i})))-4))) );
        end;
        end;
 else assignment = .;

end;

drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I write this code or Is there any shorter way? Can you help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 21:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594295#M170713</guid>
      <dc:creator>maozsoy</dc:creator>
      <dc:date>2019-10-05T21:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594299#M170716</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293869"&gt;@maozsoy&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;In principle, you seem to head in the right direction by using arrays. But there's no need for macros of any kind, sort, or shape: You need to only diligently execute a straightforward piece of array logic. Also, using A, B, etc. as values for ASSIGNMENT is precarious: Since, as you say, you have 100+ variables like SCORE* and FEE* in your real file, you don't have enough letters to mark all of them apart. Perhaps you have combinations of letters and/or digits after the underscore in the variables' names, but you aren't telling us. At any rate, below, the part of the variable name after the underscore is used, whatever it is, which precludes any such collisions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                         
  input id score_a score_b score_c score_d fee_a fee_b fee_c fee_d ;
  cards ;                                                           
111111  70  85  50    60    2  4  3  8                              
222222  80  65  80    70    9  4  5  1                              
333333  60  70  70    100   5  3  5  4                              
444444  60  90  100   100   7  2  3  2                              
555555  40  70  80    50    4  1  5  1                              
666666  75  80  60    60    9  3  2  2                              
;                                                                   
run ;                                                               
                                                                    
data want (drop = _:) ;                                             
  set have ;                                                        
  array s score_: ;                                                 
  array f fee_: ;                                                   
  do over s ;                                                       
    if f ne min (of f[*]) or s &amp;lt;= _ms then continue ;               
    _ms = s ;                                                       
    assignment = put (scan (vname (f), 2, "_"), $upcase32.) ;       
  end ;                                                             
run ;                                                               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the "max" logic vis-a-vis the auxiliary _MS variable is partly made possible by the fact that the unretained _MS is auto-set to a missing value at the top of the DATA step implied loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 01:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594299#M170716</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-06T01:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594332#M170740</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                         
  input id score_a score_b score_c score_d fee_a fee_b fee_c fee_d ;
  cards ;                                                           
111111  70  85  50    60    2  4  3  8                              
222222  80  65  80    70    9  4  5  1                              
333333  60  70  70    100   5  3  5  4                              
444444  60  90  100   100   7  2  3  2                              
555555  40  70  80    50    4  1  5  1                              
666666  75  80  60    60    9  3  2  2                              
;                                                                   
run ;                                                               
                                                                    
data want ;                                             
  set have ;                                                        
  array s{*} score_: ;                                                 
  array f{*}fee_: ; 
min=min(of f{*});
do i=1 to dim(f);
 if f{i}=min and s{i}&amp;gt;max then do;max=s{i};want=scan(vname(f{i}),-1,'_'); end;
end;
drop i min max;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2019 11:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594332#M170740</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-06T11:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594421#M170770</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;I am very pleased for your contributions.&lt;/P&gt;&lt;P&gt;Unfortunately i couldn't understand&amp;nbsp;what exactly difference "do over" and "do i=1 to dim(s)". And I guess "... then continue;" reference the next two lines, right it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition; this structure don't work when "score_..." columns and&amp;nbsp;"fee_..." columns are shuffled. For example if my data is like below, it doesn't result that i want. (I changed the order of 'score_d' and 'score_b')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have1 ;                                                         
  input id score_a score_d score_c score_b fee_a fee_b fee_c fee_d ;
  cards ;                                                           
111111  70  60  50   85    2  4  3  8                              
222222  80  70  80   65    9  4  5  1                              
333333  60  100 70   70    5  3  5  4                              
444444  60  100 100  90    7  2  3  2                              
555555  40  50  80   70    4  1  5  1                              
666666  75  60  60   80    9  3  2  2                              
;                                                                   
run ;  &lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Oct 2019 07:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594421#M170770</guid>
      <dc:creator>maozsoy</dc:creator>
      <dc:date>2019-10-07T07:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594422#M170771</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&amp;nbsp;I am very pleased for your contributions., thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But unfortunately this structure don't work when "score_..." columns and&amp;nbsp;"fee_..." columns are shuffled. For example if my data is like below, it doesn't result that i want. (I changed&amp;nbsp;the order of 'score_d' and 'score_b')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have1 ;                                                         
  input id score_a score_d score_c score_b fee_a fee_b fee_c fee_d ;
  cards ;                                                           
111111  70  60  50   85   2  4  3  8                              
222222  80  70  80   65   9  4  5  1                              
333333  60  100 70   70   5  3  5  4                              
444444  60  100 100  90   7  2  3  2                              
555555  40  50  80   70   4  1  5  1                              
666666  75  60  60   80   9  3  2  2                              
;                                                                   
run ;  &lt;/PRE&gt;&lt;P&gt;I think I need the code like below but I couldn't define macro. How can i do get macro in a loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;                                             
  set have1 ;                                                        
  array s{*} score_: ;                                                 
  array f{*}fee_: ; 

counter = 0;
do i=1 to dim(f);
if f{i} = min(of f(*)) then counter = counter + 1; else counter = counter;
end;

min=min(of f{*});

length wants $ 500;

do i=1 to dim(f);
 if f{i}=min then do;
		 if counter &amp;lt;= 1 then want=scan(vname(f{i}),-1,'_');
	else if counter &amp;gt;  1 then do;&lt;BR /&gt;            wants=catx(' ', wants, scan(vname(f{i}),-1,'_') ) into:array_wants separated by ' ';&lt;BR /&gt;            array w [*] &amp;amp;array_wants.;

            do i=1 to dim(w);
	    if w{i}=max(of w{*}) then want=scan(vname(w{i}),-1,'_');
            end;&lt;BR /&gt;          end;
	end;
end;



drop i min max;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Oct 2019 07:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594422#M170771</guid>
      <dc:creator>maozsoy</dc:creator>
      <dc:date>2019-10-07T07:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594423#M170772</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293869"&gt;@maozsoy&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;When the array is defined as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array s score_: ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it automatically creates an &lt;EM&gt;implicitly subscripted array S&lt;/EM&gt; with the array index as an automatic variable _I_ (which is automatically dropped from the output). Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do over s ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; reference to s ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;means the same as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do _i_ = 1 to dim (s) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; reference to s[_i_] ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;end ;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So. basically, there's no difference between the&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s code and mine in this respect, except that he's using an &lt;EM&gt;explicitly subsripted array&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CONTINUE within a DO loop means: If the condition preceding it is true, pass program control to the bottom of the loop (i.e. the location right before END), ignoring all instructions between it and the bottom of the loop, and go to the next iteration of the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you shuffle either SCORE* or FEE* variables, so that their suffixes don't align, you redefine the task and need to specify which variable - SCORE* or FEE* - should supply its suffix to ASSIGNMENT after the minimal FEE is found for the maximum SCORE that resolves the ties among more than one minimal FEE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand why you keep referencing some kind of macro. Macros have nothing to do with this task or code. Remember that macros are nothing but one of the means to assemble executable SAS code - and you have no code to assemble here. All you need is a straightforward (and correct according to the specs) piece of DATA step logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 07:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594423#M170772</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-07T07:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594427#M170773</link>
      <description>&lt;P&gt;If you are working with shuffled array (name suffixes not in the same order in the two sets), a bit of macro stuff may be necessary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro listvars(prefix,suffixes);
  %local i w;
  %do i=1 %to 999999;
    %let w=%scan(&amp;amp;suffixes,&amp;amp;i);
	%if %length(&amp;amp;w)=0 %then %return;
	%do; &amp;amp;prefix.&amp;amp;w%end;
	%end;
%mend;

data want (drop = _:) ;                                             
  set have ;                                                        
  array s %listvars(SCORE_,A B C D);                                                 
  array f %listvars(FEE_,A B C D);                                                   
  do over s ;                                                       
    if f ne min (of f[*]) or s &amp;lt;= _ms then continue ;               
    _ms = s ;                                                       
    assignment = put (scan (vname (f), 2, "_"), $upcase32.) ;       
  end ;                                                             
run ;          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Apart from the new array definitions, the solution is the one presented by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;. The macro just generates a list like " FEE_A FEE_B FEE_C FEE_D". You can also skip the macro and write the full lists in your program, if you prefer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding your other questions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;DO OVER essentially loops through the array, using a temporary variable _I_ as the array iterator. Essentially it is equal to DO _I_=LBOUND(&amp;lt;array&amp;gt;) TO HBOUND(&amp;lt;array&amp;gt;). This shorthand is not documented anymore, but I suspect that SAS will keep it anyway, as removing may break a lot of old programs. One word of warning:&amp;nbsp;&lt;STRONG&gt;Do not nest DO OVER&lt;/STRONG&gt;&lt;STRONG&gt; loops!&lt;/STRONG&gt;&amp;nbsp;The inner and the outer loop will use the same iterator, _I_, which will break the program.&lt;/LI&gt;
&lt;LI&gt;CONTINUE means "jump to the next iteration of the loop", so the statements inside the loop following the CONTINUE statement will not be executed.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 07 Oct 2019 07:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594427#M170773</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-07T07:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594430#M170774</link>
      <description>&lt;P&gt;Thanks for explanation of 'array' and 'continue' templates, ok.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking i need to use macro. Because the order of columns may vary in the table. But my code should not be affected this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually i mean;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a, b, c... are my products that have names differently.&lt;/P&gt;&lt;P&gt;a ==&amp;gt; fee_a,&amp;nbsp; score_a&lt;/P&gt;&lt;P&gt;b ==&amp;gt; fee_b,&amp;nbsp; score_b&lt;/P&gt;&lt;P&gt;c ==&amp;gt; fee_c, score_c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also they can called as;&lt;/P&gt;&lt;P&gt;pencil ==&amp;gt; fee_pencil, score_pencil (different features of the same product&lt;EM&gt;-pencil-&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;book ==&amp;gt; fee_book, score_book&amp;nbsp;(different features of the same product&lt;EM&gt;-book-&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;rubber ==&amp;gt; fee_rubber, score_rubber&amp;nbsp;(different features of the same product&lt;EM&gt;-rubber-&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So although their order is different (eg. score_d - score_b - fee_b - fee_d), my code structure should examine score_d for fee_d and should examine score_b for fee_b same way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope i could explain &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594430#M170774</guid>
      <dc:creator>maozsoy</dc:creator>
      <dc:date>2019-10-07T08:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594433#M170776</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You can nest DO loops over implicit arrays all you want if you define the arrays with different indices, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                                                                                                                                                                                                                   
  array ii (i) i1-i3 (1 2 3) ;                                                                                                                                                                                                                                  
  array jj (j) j1-j2 (4 5) ;                                                                                                                                                                                                                                    
  do over ii ;                                                                                                                                                                                                                                                  
    do over jj ;                                                                                                                                                                                                                                                
      put ii= jj= ;                                                                                                                                                                                                                                             
    end ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
run ;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;i1=1 j1=4
i1=1 j2=5
i2=2 j1=4
i2=2 j2=5
i3=3 j1=4
i3=3 j2=5
&lt;/PRE&gt;
&lt;P&gt;Moreover, you can create an implicit array that contains other implicit arrays as its elements - the ability woefully absent from explicitly subscripted arrays. SAS User's Guide: Basics, Version 5 Edition, pages 48-49 (45-49 about the implicit arrays in general). The functionality, despite being as of 1985, still works like a champ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 08:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594433#M170776</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-07T08:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594443#M170779</link>
      <description>&lt;P&gt;As Paul said, specified arrays&amp;nbsp; explicitly :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; s&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt; score_a score_b score_c score_d&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;                                                 
&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; f&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;} &lt;/SPAN&gt;fee_a fee_b fee_c fee_d&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Oct 2019 11:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594443#M170779</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-07T11:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594499#M170810</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;You&lt;/EM&gt; said that.&lt;/P&gt;
&lt;P&gt;I &lt;EM&gt;should have said&lt;/EM&gt; that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594499#M170810</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-07T17:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594536#M170825</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293869"&gt;@maozsoy&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;has pointed out, you just need to specify the SCORE and FEE variables to both arrays in the same &lt;EM&gt;suffix order&lt;/EM&gt;. Which one - doesn't matter, as long as it's the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simply hard code the array variables in the desired order. (Essentially, the macro invoked in your accepted solution does the same thing, except that you don't have to specify the prefixes.) But this is hardly a satisfactory solution since, as you've informed us, the list of the variables can be 100+ long: Are you going to type them all or type their suffixes into the macro call?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good code is dynamic and shouldn't depend on this kind of vagaries. In this case, the simplest is to pre-create two SCORE and FEE variable lists, both ordered by the variable suffix and feed them into the already working code I offered originally. This way, the solution doesn't depend at all on the order in which the SCORE and FEE variables are listed in HAVE as long as for each FEE suffix there's the same and only one SCORE suffix:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                                                                                                                                                     
  input id score_a score_d score_c score_b                                                                                                                                                                                                                      
           fee_a   fee_b   fee_c   fee_d                                                                                                                                                                                                                        
  ;                                                                                                                                                                                                                                                             
  cards ;                                                                                                                                                                                                                                                       
111111  70   60  50  85  2  4  3  8                                                                                                                                                                                                                             
222222  80   70  80  65  9  4  5  1                                                                                                                                                                                                                             
333333  60  100  70  70  5  3  5  4                                                                                                                                                                                                                             
444444  60  100 100  90  7  2  3  2                                                                                                                                                                                                                             
555555  40   50  80  70  4  1  5  1                                                                                                                                                                                                                             
666666  75   60  60  80  9  3  2  2                                                                                                                                                                                                                             
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
proc sql noprint ;                                                                                                                                                                                                                                              
  select name into :s separated by " " from dictionary.columns                                                                                                                                                                                                  
  where  libname="WORK" and memname="HAVE" and lower (name) like 'score_%'                                                                                                                                                                                      
  order  lower (name) ;                                                                                                                                                                                                                                         
  select name into :f separated by " " from dictionary.columns                                                                                                                                                                                                  
  where  libname="WORK" and memname="HAVE" and lower (name) like 'fee_%'                                                                                                                                                                                        
  order  lower (name) ;                                                                                                                                                                                                                                         
quit ;                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                
data want (drop = _:) ;                                                                                                                                                                                                                                         
  set have ;                                                                                                                                                                                                                                                    
  array s &amp;amp;s ;                                                                                                                                                                                                                                                  
  array f &amp;amp;f ;                                                                                                                                                                                                                                                  
  do over s ;                                                                                                                                                                                                                                                   
    if f ne min (of f[*]) or s &amp;lt;= _ms then continue ;                                                                                                                                                                                                           
    _ms = s ;                                                                                                                                                                                                                                                   
    assignment = put (scan (vname (f), 2, "_"), $upcase32.) ;                                                                                                                                                                                                   
  end ;                                                                                                                                                                                                                                                         
run ;                           
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It does involve a couple of macro variables but it's not at all the same as using a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, in reality you don't have to even use any macro variables at all - indeed, don't even need to have the variable name lists sorted. In this case, it simply means that for a given FEE_suffix you need to locate the SCORE_suffix variable with the same suffix, which in turn means that the SCORE suffixes and their corresponding array S indices should be stored in some kind of lookup table. Below, this table takes on the form of the temporary array Z with enough elements to cover the territory (i.e. it is assumed that you have fewer than 10000 SCORE and FEE variables - if not enough, just add another 9 to the array size):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = _:) ;                                                                                                                                                                                                                                         
  set have ;                                                                                                                                                                                                                                                    
  array s (_s) score_: ;                                                                                                                                                                                                                                        
  array f (_f) fee_: ;                                                                                                                                                                                                                                          
  array z [9999] $ 26 _temporary_ ;                                                                                                                                                                                                                             
  if _n_ = 1 then do over s ;                                                                                                                                                                                                                                   
    z[_s] = upcase (substr (vname (s), 1 + find (vname (s), "_"))) ;                                                                                                                                                                                            
  end ;                                                                                                                                                                                                                                                         
  length _sfx assignment $ 26 ; *32-length('score') ;                                                                                                                                                                                                           
  do over f ;                                                                                                                                                                                                                                                   
    _sfx = upcase (substr (vname (f), 1 + find (vname (f), "_"))) ;                                                                                                                                                                                             
    _s = whichc (_sfx, of z[*]) ;                                                                                                                                                                                                                               
    if f ne min (of f[*]) or s &amp;lt;= _ms then continue ;                                                                                                                                                                                                           
    _ms = s ;                                                                                                                                                                                                                                                   
    assignment = _sfx ;                                                                                                                                                                                                                                         
  end ;                                                                                                                                                                                                                                                         
run ;         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code is basically the same as the original, except now the index _S is not the same as _F but is dictated by the suffix of FEE in the current iteration of the DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some folks poo-poo the concept of allocating a "big enough" lookup table, even if it's well justified (as in the case above). But as of the current state of the SAS software, it doesn't have to be relied upon, and the table can be made dynamic instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = _:) ;                                                            
  set have ;                                                                       
  array s (_s) score_: ;                                                           
  array f (_f) fee_: ;                                                             
  if _n_ = 1 then do ;                                                             
    dcl hash z () ;                                                                
    z.definekey ("_sfx") ;                                                         
    z.definedata ("_s") ;                                                          
    z.definedone () ;                                                              
    do over s ;                                                                    
      z.add (key:upcase (substr (vname (s), 1 + find (vname (s), "_"))), data:_s) ;
    end ;                                                                          
  end ;                                                                            
  length _sfx assignment $ 26 ; *32-length('score') ;                              
  do over f ;                                                                      
    _sfx = upcase (substr (vname (f), 1 + find (vname (f), "_"))) ;                
    z.find() ;                                                                     
    if f ne min (of f[*]) or s &amp;lt;= _ms then continue ;                              
    _ms = s ;                                                                      
    assignment = _sfx ;                                                            
  end ;                                                                            
run ;                                                                              
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Above the index _S needed to ID the required SCORE variable is extracted from the hash table Z instead of array Z. The result, of course, is the same, except that with a large number of variables SCORE and FEE, the hash table is faster since it searches for _SFX in O(1) time, while WHICHN does the same in O(N) time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 19:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594536#M170825</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-07T19:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594688#M170905</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;I'm curious here. What does an implicit array, that contains other implicit arrays look like?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 10:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594688#M170905</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-08T10:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594921#M171055</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Curiosity must be satisfied ;). Don't have my V5 Guide with me, so just off the top of my head:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                                                                                                                                                                                                                   
  array a (i) a1-a4 (11 21 31 41) ;                                                                                                                                                                                                                             
  array b (i) b1-b4 (21 22 23 24) ;                                                                                                                                                                                                                             
  array c (i) c1-c4 (31 32 33 34) ;                                                                                                                                                                                                                             
  array abc a b c ;                                                                                                                                                                                                                                             
  do over abc ;                                                                                                                                                                                                                                                 
    do i = 1 to dim (a) ;                                                                                                                                                                                                                                       
      put abc @ ;                                                                                                                                                                                                                                               
    end ;                                                                                                                                                                                                                                                       
    put ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
  put ;                                                                                                                                                                                                                                                         
  do i = 1 to dim (a) ;                                                                                                                                                                                                                                         
    do over abc ;                                                                                                                                                                                                                                               
      put abc @ ;                                                                                                                                                                                                                                               
    end ;                                                                                                                                                                                                                                                       
    put ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
run ;         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which prints in the log:&lt;/P&gt;
&lt;PRE&gt;11 21 31 41
21 22 23 24
31 32 33 34

11 21 31
21 22 32
31 23 33
41 24 34
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 00:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/594921#M171055</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-09T00:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to find min variable when there are two or more value exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/596058#M171576</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;very cool. Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 11:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-min-variable-when-there-are-two-or-more-value-exist/m-p/596058#M171576</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-13T11:21:51Z</dc:date>
    </item>
  </channel>
</rss>

