<?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 A little help with Arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441086#M110288</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to specify when any one of the Questions is a 5 (the questions range from 1 to 5), using arrays. Unfortunately, the program I have written doesn't work. Perhaps someone can offer some assistance. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------&lt;/P&gt;&lt;P&gt;Libname Learn'/folders/myfolders/Learn' ;&lt;BR /&gt;&lt;BR /&gt;Data Survey2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Set Learn.Survey2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Array QuesNum(*)&amp;nbsp; $ Ques1-Ques5 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to dim(QuesNum) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaxQues = Max(of QuesNum) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If MaxQues = 5 then Any = 'Yes' ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else Any = 'No' ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Mar 2018 01:10:16 GMT</pubDate>
    <dc:creator>ManitobaMoose</dc:creator>
    <dc:date>2018-03-01T01:10:16Z</dc:date>
    <item>
      <title>A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441086#M110288</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to specify when any one of the Questions is a 5 (the questions range from 1 to 5), using arrays. Unfortunately, the program I have written doesn't work. Perhaps someone can offer some assistance. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------&lt;/P&gt;&lt;P&gt;Libname Learn'/folders/myfolders/Learn' ;&lt;BR /&gt;&lt;BR /&gt;Data Survey2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Set Learn.Survey2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Array QuesNum(*)&amp;nbsp; $ Ques1-Ques5 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to dim(QuesNum) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaxQues = Max(of QuesNum) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If MaxQues = 5 then Any = 'Yes' ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else Any = 'No' ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 01:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441086#M110288</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-03-01T01:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441094#M110292</link>
      <description>&lt;P&gt;Questions for you to get started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you certain that QUES1 through QUES5 are the names of the variables you will be working with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know whether they are character or numeric?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 02:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441094#M110292</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-01T02:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441095#M110293</link>
      <description>&lt;P&gt;1)&amp;nbsp; &amp;nbsp;The line&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;MaxQues = Max(of QuesNum) ;&lt;/SPAN&gt;&lt;/STRONG&gt; is &lt;FONT color="#FF0000"&gt;erronous&lt;/FONT&gt;, as MAX function needs a variable as argument&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; while QuesNum is an array name and not a avriable.&lt;/P&gt;
&lt;P&gt;2) Why do you use the max function is not clear !&lt;/P&gt;
&lt;P&gt;3) You closed the DO loop with END without having any code inside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I assume you want to check - either&amp;nbsp;&lt;STRONG&gt;i=5&lt;/STRONG&gt;&amp;nbsp; or&amp;nbsp; &lt;STRONG&gt;QuestNum(i)=5&amp;nbsp;&lt;/STRONG&gt; and then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;assign the Any variable to YES or NO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; That should be inside the do loop (i.e. between the DO statement and the END statement).&lt;/P&gt;
&lt;P&gt;4) Your input is in &lt;STRONG&gt;one&lt;/STRONG&gt; &lt;STRONG&gt;row&lt;/STRONG&gt; of 5 variables:&amp;nbsp; &amp;nbsp;Ques1 - Ques5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;You defined only one new variable&amp;nbsp;ANY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; You need &lt;U&gt;either&lt;/U&gt; define ANY1 - ANY5 as a new array and assign the YES/NO to ANYX(i)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; assuming Array&amp;nbsp;&lt;STRONG&gt;anyx any1-any5;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;U&gt;or&lt;/U&gt;&amp;nbsp; add OUTPUT; statment to result in 5 output rows&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 02:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441095#M110293</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-03-01T02:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441101#M110299</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MaxQues = Max(of QuesNum(*)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You should also check the WHICHN&amp;nbsp;function, and you don't necessarily even need an array declaration in this case.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Find5 = WHICHN(5, of ques1-ques5);
MaxQuest = max(of ques1-ques5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Relevant section of the&amp;nbsp;documentation that explains variable lists and all the variations, table at the bottom is&amp;nbsp;&lt;/SPAN&gt;handy:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 03:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441101#M110299</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-01T03:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441124#M110305</link>
      <description>&lt;P&gt;Ok, I figured it out. Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Libname Learn'/folders/myfolders/Learn' ;&lt;BR /&gt;&lt;BR /&gt;Data Survey2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Set Learn.Survey2 (rename=&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; (Ques1 = CharQues1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ques2 = CharQues2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ques3 = CharQues3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ques4 = CharQues4&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ques5 = CharQues5)) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Q1 = Input(CharQues1, 8.) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Q2 = Input(CharQues2, 8.) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Q3 = Input(CharQues3, 8.) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Q4 = Input(CharQues4, 8.) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Q5 = Input(CharQues5, 8.) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Array QuesNum(*)&amp;nbsp; $ Ques1-Ques5 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to dim(QuesNum) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Array AnyX(*)&amp;nbsp; Q1-Q5 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to dim(AnyX) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Max(of Q1-Q5) = 5 then Any5s = 'Yes' ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else Any5s = 'No' ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop i CharQues1-CharQues5 Ques1-Ques5 ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 05:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441124#M110305</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-03-01T05:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441140#M110311</link>
      <description>&lt;P&gt;You can shorten your code to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Learn'/folders/myfolders/Learn' ;

Data Survey2 ;
    Set Learn.Survey2;
        retain Any5s 'No' ;                     
        length Q1-Q5 3  Any5s $3 ;
    
    Array QuesNum(*)  $ Ques1-Ques5 ;
    Array Qx(*)  Q1-Q5 ;
	
    do i = 1 to dim(QuesNum) ;
	 Qx(i) = input(QuesNum(i));      
	 if Qx(i) = 5 then Any5s = 'Yes' ;&lt;BR /&gt;         /* next 2 lines are for debug only - check in the log */&lt;BR /&gt;            Q = Qx(i);&lt;BR /&gt;            PUT i=  Q= Any5s= ;
    end ;
    
    drop i Ques1-Ques5 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;or even shorter to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Learn'/folders/myfolders/Learn' ;

Data Survey2 ;
    Set Learn.Survey2;&lt;BR /&gt;        length Q $8   Any5s $3 ;
        retain Any5s 'No ' ;                     
    
    Array QuesNum(*)  $ Ques1-Ques5 ;
	
    do i = 1 to dim(QuesNum) ;
       if QuesNum(i) = '5' then Any5s = 'Yes' ;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;         /* next 2 lines are for debug only - check in the log */&lt;BR /&gt;            Q = QuesNum(i);&lt;BR /&gt;            PUT i=  Q= Any5s= ;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;    end ; &lt;BR /&gt;    drop i Ques1-Ques5 ; &lt;BR /&gt;run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;run and compare the two solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 09:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441140#M110311</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-03-01T09:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: A little help with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441142#M110312</link>
      <description>&lt;P&gt;Way too overthought that, you are simply searching for "5" in some variables so:&lt;/P&gt;
&lt;PRE&gt;data survey2;
  set learn.survey2;
  any=ifc(index(cats(of ques:),"5"),"Yes","No");
run;&lt;/PRE&gt;
&lt;P&gt;What this does is the cats puts all the variables together, index returns &amp;gt;0 if 5 is found, if that is true (any non zero is true) then use test Yes, otherwise use text no.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 09:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-little-help-with-Arrays/m-p/441142#M110312</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-01T09:17:26Z</dc:date>
    </item>
  </channel>
</rss>

