<?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 an array on multiple variables for output to one variable (9.4) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414147#M101456</link>
    <description>&lt;P&gt;It's case sensitive. Is it 'yes' or 'Yes'?&lt;/P&gt;
&lt;P&gt;And if that doesn't work, check for trailing spaces or such.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Nov 2017 21:16:27 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-16T21:16:27Z</dc:date>
    <item>
      <title>Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414133#M101446</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 21 variables of results (rslt_1 - rslt_21). Values within each variable are 'yes', 'no', 'unknown' and blanks. I am interested in one variable, lets call it helpme, that will tell me whether or not a subject ever had a 'yes' in any of the 21 results. If not, then I want the value of helpme to be either no or none if results were no, unknown, or blank. For example, I would like my final data to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rslt_1&amp;nbsp; &amp;nbsp;rslt_2&amp;nbsp; &amp;nbsp;rslt_3&amp;nbsp; ...&amp;nbsp; &amp;nbsp;rslt_21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; helpme&lt;/P&gt;&lt;P&gt;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; no&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;unknown&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;&lt;P&gt;no&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;no&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;&lt;P&gt;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;&lt;P&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;none&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use an array, right? But I'm getting stuck on creating the new variable. Here's the code I have tried, which creates "helpme" but without any values and SAS tries to convert my character variables to numeric.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want (drop=i);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array rsltarray (21) rslt_1-rslt_21;&lt;/P&gt;&lt;P&gt;do i=1 to 21;&lt;/P&gt;&lt;P&gt;if rsltarray(i) in ('yes') then helpme='yes';&lt;/P&gt;&lt;P&gt;else if rsltarray(i) in ('no', 'unknown') then helpme='no';&lt;/P&gt;&lt;P&gt;else if rsltarray(i) in ('') then helpme='none';&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 20:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414133#M101446</guid>
      <dc:creator>aeb</dc:creator>
      <dc:date>2017-11-16T20:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414136#M101449</link>
      <description>&lt;P&gt;Look up the WHICHC function instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/178071"&gt;@aeb&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 21 variables of results (rslt_1 - rslt_21). Values within each variable are 'yes', 'no', 'unknown' and blanks. I am interested in one variable, lets call it helpme, that will tell me whether or not a subject ever had a 'yes' in any of the 21 results. If not, then I want the value of helpme to be either no or none if results were no, unknown, or blank. For example, I would like my final data to look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rslt_1&amp;nbsp; &amp;nbsp;rslt_2&amp;nbsp; &amp;nbsp;rslt_3&amp;nbsp; ...&amp;nbsp; &amp;nbsp;rslt_21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; helpme&lt;/P&gt;
&lt;P&gt;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; no&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;unknown&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;
&lt;P&gt;no&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;no&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;
&lt;P&gt;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;
&lt;P&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;none&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use an array, right? But I'm getting stuck on creating the new variable. Here's the code I have tried, which creates "helpme" but without any values and SAS tries to convert my character variables to numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want (drop=i);&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array rsltarray (21) rslt_1-rslt_21;&lt;/P&gt;
&lt;P&gt;do i=1 to 21;&lt;/P&gt;
&lt;P&gt;if rsltarray(i) in ('yes') then helpme='yes';&lt;/P&gt;
&lt;P&gt;else if rsltarray(i) in ('no', 'unknown') then helpme='no';&lt;/P&gt;
&lt;P&gt;else if rsltarray(i) in ('') then helpme='none';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414136#M101449</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-16T21:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414137#M101450</link>
      <description>&lt;P&gt;If your variables were more sensible coded as 1,0 and a special missing for Unknown this would be pretty trivial as you could use MAX and Min functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code as written will always have the value for the last item in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other functions than equality available:&lt;/P&gt;
&lt;PRE&gt;data want (drop=i);
   set have;
   array rsltarray (21) rslt_1-rslt_21;
   if whichc('yes',of rsltarray(*)) &amp;gt; 0 then helpme='yes'; 
   else if cmiss(of rsltarray(*) = 21 then helpme='none';
   else helpme='no';
run;&lt;/PRE&gt;
&lt;P&gt;whichc returns the number of the first word in the list (here the array) that the first string value appears, or 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CMISS counts the missing string values, if 21 then all are missing&lt;/P&gt;
&lt;P&gt;otherwise the has to be at least one "no" if your data description is correct.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414137#M101450</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-16T21:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414142#M101452</link>
      <description>&lt;P&gt;The first thing to resolve is what is actually in your data.&amp;nbsp; When you say that SAS is converting your variables to numeric, the most likely situation is that they are already numeric.&amp;nbsp; They just appear to be character, because there is a format attached to them.&amp;nbsp; Run a PROC CONTENTS on your data set to see what is actually in there.&amp;nbsp; (There are other possibilities, such as the variable names actually having a slightly different spelling.)&amp;nbsp; Also run 2 PROC FREQs to see what the values are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;tables rslt_1-rslt_21;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;tables rslt_1-rslt_21;&lt;/P&gt;
&lt;P&gt;format rslt_1-rslt_21;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once we know what is in there, the programming can begin.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414142#M101452</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-16T21:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414146#M101455</link>
      <description>&lt;P&gt;Variables are definitely character (I renamed my variables in the posting for simplicity). Attempting the WHICHC function suggested, but it is overlooking the "yes" responses. Only getting "no" and "none" in my final output. I inherited a rough data set, thanks for your patience!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&lt;BR /&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;asprslt_1&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;$7.&lt;/TD&gt;&lt;TD&gt;$7.&lt;/TD&gt;&lt;TD&gt;asprslt_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;asprslt_2&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;$3.&lt;/TD&gt;&lt;TD&gt;$3.&lt;/TD&gt;&lt;TD&gt;asprslt_2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;asprslt_3&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;$3.&lt;/TD&gt;&lt;TD&gt;$3.&lt;/TD&gt;&lt;TD&gt;asprslt_3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414146#M101455</guid>
      <dc:creator>aeb</dc:creator>
      <dc:date>2017-11-16T21:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414147#M101456</link>
      <description>&lt;P&gt;It's case sensitive. Is it 'yes' or 'Yes'?&lt;/P&gt;
&lt;P&gt;And if that doesn't work, check for trailing spaces or such.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414147#M101456</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-16T21:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414148#M101457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/178071"&gt;@aeb&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Variables are definitely character (I renamed my variables in the posting for simplicity). Attempting the WHICHC function suggested, but it is overlooking the "yes" responses. Only getting "no" and "none" in my final output. I inherited a rough data set, thanks for your patience!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No data=&amp;gt; no tested code&lt;/P&gt;
&lt;P&gt;No posted code / log =&amp;gt; we have no idea what you actually ran.&lt;/P&gt;
&lt;P&gt;It appears most likely that you may have missed the first "else" in the code that I suggested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW your example description of 3 variables indicates that ONLY asprslt_1 of the three shown could have the value of "unknown" due to the length of the variable.&lt;/P&gt;
&lt;P&gt;Which indicates someone relied on Proc Import at some point in the past to read the data instead of forcing all of the asprslt variables to use the same informat/ length which should be the case if they are using the same measurement scale.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414148#M101457</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-16T21:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array on multiple variables for output to one variable (9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414149#M101458</link>
      <description>&lt;P&gt;This was correct as well. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 21:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-on-multiple-variables-for-output-to-one-variable/m-p/414149#M101458</guid>
      <dc:creator>aeb</dc:creator>
      <dc:date>2017-11-16T21:20:20Z</dc:date>
    </item>
  </channel>
</rss>

