<?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 a Do Loop for an undeclared Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519463#M140695</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243966"&gt;@jdchang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to subset a large dataset that has a couple sequentially named variables (e.g. dx1-dx15, proc1-proc15). I did not create these variables, but am wondering if I can reference them in a do loop in order to conditionally check their contents without declaring them as an array - or if there is another manner to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this moment I've been writing separate if statements to check each variable individually or including each variable and its condition separately in a where statement, which has worked thus far. I'm just wondering if there's a more elegant way to code it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say that it would be better to use an explicitly defined array. Since the array definition accepts things like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array d dx1-dx15;&lt;/P&gt;
&lt;P&gt;to define the array then there isn't much extra work involved.&lt;/P&gt;
&lt;P&gt;Second then you have tools involving arrays like the VNAME function. So suppose I am checking some conditions on an array such as&lt;/P&gt;
&lt;P&gt;the value should be in a range of values then I can do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;do i=1 to dim(d);
   if d[i] &amp;lt; 10 then do:
      var= vname(d[i]);
      put var +1 "is &amp;lt; 10 on record " _n_;
   end;
   if d[i] &amp;gt; 50 then do:
      var= vname(d[i]);
      put var +1 "is &amp;gt; 50 on record " _n_;
   end;
end;&lt;/PRE&gt;
&lt;P&gt;If a group of variables have similar required tests they can all be in an array used for that test. So if both your DX and PROC variables should not have any missing you could have them in a single array just for that test assuming they are of the same variable type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Dec 2018 16:15:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-12-07T16:15:56Z</dc:date>
    <item>
      <title>Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519453#M140690</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to subset a large dataset that has a couple sequentially named variables (e.g. dx1-dx15, proc1-proc15). I did not create these variables, but am wondering if I can reference them in a do loop in order to conditionally check their contents without declaring them as an array - or if there is another manner to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this moment I've been writing separate if statements to check each variable individually or including each variable and its condition separately in a where statement, which has worked thus far. I'm just wondering if there's a more elegant way to code it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519453#M140690</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-12-07T16:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519455#M140691</link>
      <description>&lt;P&gt;Why don't you want to put them in an array? Seems like the way to go&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519455#M140691</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-07T16:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519457#M140692</link>
      <description>&lt;P&gt;I'd be fine with doing that. Could I use the already established variable names when creating the array so that the variable names don't change? These are also formatted variables and it'd be great if I could keep them as is, but if there's no avoiding it then I'll bite the bullet.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519457#M140692</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-12-07T16:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519463#M140695</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243966"&gt;@jdchang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to subset a large dataset that has a couple sequentially named variables (e.g. dx1-dx15, proc1-proc15). I did not create these variables, but am wondering if I can reference them in a do loop in order to conditionally check their contents without declaring them as an array - or if there is another manner to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this moment I've been writing separate if statements to check each variable individually or including each variable and its condition separately in a where statement, which has worked thus far. I'm just wondering if there's a more elegant way to code it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say that it would be better to use an explicitly defined array. Since the array definition accepts things like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array d dx1-dx15;&lt;/P&gt;
&lt;P&gt;to define the array then there isn't much extra work involved.&lt;/P&gt;
&lt;P&gt;Second then you have tools involving arrays like the VNAME function. So suppose I am checking some conditions on an array such as&lt;/P&gt;
&lt;P&gt;the value should be in a range of values then I can do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;do i=1 to dim(d);
   if d[i] &amp;lt; 10 then do:
      var= vname(d[i]);
      put var +1 "is &amp;lt; 10 on record " _n_;
   end;
   if d[i] &amp;gt; 50 then do:
      var= vname(d[i]);
      put var +1 "is &amp;gt; 50 on record " _n_;
   end;
end;&lt;/PRE&gt;
&lt;P&gt;If a group of variables have similar required tests they can all be in an array used for that test. So if both your DX and PROC variables should not have any missing you could have them in a single array just for that test assuming they are of the same variable type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519463#M140695</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-07T16:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519467#M140696</link>
      <description>&lt;P&gt;Neither variable names nor formats will change &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Arrays are just groupings of variables for smarter processing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do something along these line &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array dx {*} dx1-dx15;
   do i=1 to dim(dx);
      if dx[i] =  0 then output; /* Or do something else */
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519467#M140696</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-07T16:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Do Loop for an undeclared Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519471#M140698</link>
      <description>&lt;P&gt;Thanks! I've only ever used the array statement to create variables and wasn't sure if it could be used to reference already established variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 16:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Do-Loop-for-an-undeclared-Array/m-p/519471#M140698</guid>
      <dc:creator>jdchang</dc:creator>
      <dc:date>2018-12-07T16:32:25Z</dc:date>
    </item>
  </channel>
</rss>

