<?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: Conditional Statement with Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461227#M117296</link>
    <description>&lt;P&gt;If your trying to find the max value from all the columns in a row then you don't need the DO Loop. Since you have the DO loop the array will substitute only one value (i) at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You code will resolve to :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If Max(Ques1) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ; &lt;BR /&gt;If Max(Ques2) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ; &lt;BR /&gt;If Max(Ques3) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ;&lt;/P&gt;
&lt;P&gt;So on ..............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to perform something like :&lt;/P&gt;
&lt;P&gt;If Max(of Ques1-Ques5) eq 5 then Any5 = 'Yes' ;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Else Any5 = 'No' ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to remove the DO LOOP&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num1 num2 num3 num4 num5;
datalines;
1 2 3 4 5
;
run;
data want;
set have;
array num_5{*} num1-num5;
IF MAX(of num_5[*])=5 then val="YES";
ELSE Val="NO";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 May 2018 00:38:54 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-05-10T00:38:54Z</dc:date>
    <item>
      <title>Conditional Statement with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461226#M117295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have mostly figure out arrays, but for some reason, this is not responding as I would expect. I thought that since the condition that the maximum of the array is 5 in some cases, that Any5 = 'Yes'. But, in all cases, Any5 = 'No'. This will be clear when you read the code. Why isn't Any5 = 'Yes' when at least 1 of the Ques1-Ques5 is 5? I realize that there may be more efficient ways to do this, but the point here is to learn how to use arrays. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data review.Any5 ; 
	Set Learn.survey2(rename=(Ques1 = CharQ1
						      Ques2 = CharQ2	
						      Ques3 = CharQ3
						      Ques4 = CharQ4
						      Ques5 = CharQ5)) ; 
	Ques1 = input(CharQ1,5.) ;
	Ques2 = input(CharQ2,5.) ;	
	Ques3 = input(CharQ3,5.) ;	
	Ques4 = input(CharQ4,5.) ;	
	Ques5 = input(CharQ5,5.) ;
	Array FindAny5{*} Ques1-Ques5 ; 
	Do i = 1 to dim(FindAny5) ; 
		If Max(FindAny5{i}) eq 5 then Any5 = 'Yes' ; 
		Else Any5 = 'No' ; 
	End ; 
	Drop i CharQ1-CharQ5  ;
Run ; 
	
	
Proc print data=review.Any5 noobs ; 
run ; &lt;/PRE&gt;</description>
      <pubDate>Thu, 10 May 2018 00:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461226#M117295</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-05-10T00:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Statement with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461227#M117296</link>
      <description>&lt;P&gt;If your trying to find the max value from all the columns in a row then you don't need the DO Loop. Since you have the DO loop the array will substitute only one value (i) at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You code will resolve to :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;If Max(Ques1) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ; &lt;BR /&gt;If Max(Ques2) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ; &lt;BR /&gt;If Max(Ques3) eq 5 then Any5 = 'Yes' ; &lt;BR /&gt; Else Any5 = 'No' ;&lt;/P&gt;
&lt;P&gt;So on ..............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to perform something like :&lt;/P&gt;
&lt;P&gt;If Max(of Ques1-Ques5) eq 5 then Any5 = 'Yes' ;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Else Any5 = 'No' ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to remove the DO LOOP&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num1 num2 num3 num4 num5;
datalines;
1 2 3 4 5
;
run;
data want;
set have;
array num_5{*} num1-num5;
IF MAX(of num_5[*])=5 then val="YES";
ELSE Val="NO";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 May 2018 00:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461227#M117296</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-10T00:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Statement with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461363#M117357</link>
      <description>&lt;P&gt;Since sometimes you can't use a simple function as in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;'s solution here is an approach using LEAVE.&lt;/P&gt;
&lt;P&gt;The LEAVE instruction terminates a loop when encountered. The code tests an exact numeric value and when (if) found sets the flag value and exits the loop the first time it is encountered. A possibly useful side affect is that the value of the loop counter will have the value of the index where the true condition was encountered. So if i=3 then you know for that record the third element of the array has the value 5.&lt;/P&gt;
&lt;PRE&gt;Data review.Any5 ; 
	Set Learn.survey2(rename=(Ques1 = CharQ1
					  Ques2 = CharQ2	
					  Ques3 = CharQ3
					  Ques4 = CharQ4
					  Ques5 = CharQ5)) ; 
	Ques1 = input(CharQ1,5.) ;
	Ques2 = input(CharQ2,5.) ;	
	Ques3 = input(CharQ3,5.) ;	
	Ques4 = input(CharQ4,5.) ;	
	Ques5 = input(CharQ5,5.) ;
	Array FindAny5{*} Ques1-Ques5 ; 
	Do i = 1 to dim(FindAny5) ; 
		If FindAny5{i} eq 5 then do;
         Any5 = 'Yes' ; 
         Leave;
      end;
		Else Any5 = 'No' ; 
	End ; 
	Drop i CharQ1-CharQ5  ;
Run ; 
	
	
Proc print data=review.Any5 noobs ; 
run ;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 May 2018 16:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Statement-with-Array/m-p/461363#M117357</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-10T16:08:59Z</dc:date>
    </item>
  </channel>
</rss>

