<?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: Array with Do Until? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470083#M120314</link>
    <description>&lt;P&gt;Best is to provide example data in the form of a data step. Then there are no questions about variable type, name or characteristics. Also code can be tested against the supplied data.&lt;/P&gt;
&lt;P&gt;Also best is to post code in a code box opened using the forum {I} icon to preserve formatting.&lt;/P&gt;
&lt;PRE&gt;data have;
  input subject    None      Discomfort       Bad_Vision      Other;
datalines;
12345 1  .   .  .
12345 .  1   .  .
12345 .  1   1  .
12345 .  1   .  1
12345 .  1   1  1
12345 .  .   .  1
run;

data want;
   set have;
   array a None Discomfort Bad_vision Other;
   array var{3} $ 10;
   count=0;
   do i=1 to dim(a);
      if a[i] = 1 then do;
         count=count+1;
         var[count]=vname(a[i]);
      end;
   end;
   keep subject var: ;
run;
      &lt;/PRE&gt;
&lt;P&gt;The above works for your example. If you ever have cases where NONE is one and the other variables are populated as well then the solution may require having a fourth variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the function VNAME gets the name of a variable referenced as an array element.&lt;/P&gt;
&lt;P&gt;The VAR:&amp;nbsp; with the colon is a short cut list that refers to all variables whose names start with VAR;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jun 2018 20:05:01 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-06-13T20:05:01Z</dc:date>
    <item>
      <title>Array with Do Until?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470066#M120307</link>
      <description>&lt;P&gt;I need to create 3 variables(var1 var2 var3) based upon the occurrence of conditions within the subject. I have the input dataset example and output dataset example below. I think and array with do until might work but I am not sure how to implement. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input Dataset:&amp;nbsp;&lt;/P&gt;&lt;P&gt;subject&amp;nbsp; &amp;nbsp; None&amp;nbsp; &amp;nbsp; &amp;nbsp; Discomfort&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Bad_Vision&amp;nbsp; &amp;nbsp; &amp;nbsp; Other&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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;1&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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;1&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;12345&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output Dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Subject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var3&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NONE&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Discomfort&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Discomfort&amp;nbsp; &amp;nbsp; &amp;nbsp;Bad_vision&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Discomfort&amp;nbsp; &amp;nbsp; &amp;nbsp;Other&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Discomfort&amp;nbsp; &amp;nbsp; &amp;nbsp;Bad vision&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Other&amp;nbsp;&lt;BR /&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Other&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 19:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470066#M120307</guid>
      <dc:creator>gpv2000</dc:creator>
      <dc:date>2018-06-13T19:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Array with Do Until?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470083#M120314</link>
      <description>&lt;P&gt;Best is to provide example data in the form of a data step. Then there are no questions about variable type, name or characteristics. Also code can be tested against the supplied data.&lt;/P&gt;
&lt;P&gt;Also best is to post code in a code box opened using the forum {I} icon to preserve formatting.&lt;/P&gt;
&lt;PRE&gt;data have;
  input subject    None      Discomfort       Bad_Vision      Other;
datalines;
12345 1  .   .  .
12345 .  1   .  .
12345 .  1   1  .
12345 .  1   .  1
12345 .  1   1  1
12345 .  .   .  1
run;

data want;
   set have;
   array a None Discomfort Bad_vision Other;
   array var{3} $ 10;
   count=0;
   do i=1 to dim(a);
      if a[i] = 1 then do;
         count=count+1;
         var[count]=vname(a[i]);
      end;
   end;
   keep subject var: ;
run;
      &lt;/PRE&gt;
&lt;P&gt;The above works for your example. If you ever have cases where NONE is one and the other variables are populated as well then the solution may require having a fourth variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the function VNAME gets the name of a variable referenced as an array element.&lt;/P&gt;
&lt;P&gt;The VAR:&amp;nbsp; with the colon is a short cut list that refers to all variables whose names start with VAR;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 20:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470083#M120314</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-13T20:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Array with Do Until?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470108#M120322</link>
      <description>&lt;P&gt;Thank you. I will keep in mind the points you mentioned about data. Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 20:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-with-Do-Until/m-p/470108#M120322</guid>
      <dc:creator>gpv2000</dc:creator>
      <dc:date>2018-06-13T20:37:37Z</dc:date>
    </item>
  </channel>
</rss>

