<?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 output from array do loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235556#M55098</link>
    <description>&lt;P&gt;Hi!&amp;nbsp; I am trying to figure out the proper way to complete an array do loop.&amp;nbsp; I have 10 variables within a larger table that start with DX&amp;nbsp; (DX1, DX2, DX3...to DX10).&amp;nbsp;&amp;nbsp; I need to know if any values that start with '493' are in the DX5-DX10 variable range.&amp;nbsp; If yes, then output the observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I have so far (but it&amp;nbsp;may all be wrong!).&amp;nbsp; &amp;nbsp;I can't figure out&amp;nbsp;how to output the observation...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test_dxcheck;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;array&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; dx(*) DX5-DX10;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; i= &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;10&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; dx(i)=: &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'493'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;????&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Thanks!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Nov 2015 21:08:07 GMT</pubDate>
    <dc:creator>jenim514</dc:creator>
    <dc:date>2015-11-19T21:08:07Z</dc:date>
    <item>
      <title>output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235556#M55098</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I am trying to figure out the proper way to complete an array do loop.&amp;nbsp; I have 10 variables within a larger table that start with DX&amp;nbsp; (DX1, DX2, DX3...to DX10).&amp;nbsp;&amp;nbsp; I need to know if any values that start with '493' are in the DX5-DX10 variable range.&amp;nbsp; If yes, then output the observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I have so far (but it&amp;nbsp;may all be wrong!).&amp;nbsp; &amp;nbsp;I can't figure out&amp;nbsp;how to output the observation...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test_dxcheck;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;array&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; dx(*) DX5-DX10;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; i= &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;10&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; dx(i)=: &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'493'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;????&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Thanks!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 21:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235556#M55098</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-19T21:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235561#M55101</link>
      <description>&lt;P&gt;You haven't described exactly what you want to do when found. Output a value, write a message to the log or what.&lt;/P&gt;
&lt;P&gt;Also what do you do if more than one of the variables has the behavior? Do the action only once or repeat for each match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your basically there though you would get an array out of bounds for&amp;nbsp;i = 6 as written. Suppose you want to write a message to the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_dxcheck;
   set have;
   array dx(*) DX5-DX10;
   do i= 1 to dim(dx);
      if dx(i)=: '493' then do put "Value found at position " I  dx[I];
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you want to output the observation only once for the first match&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_dxcheck;
   set have;
   array dx(*) DX5-DX10;
   do i= 1 to dim(dx);
      if dx(i)=: '493' then do ;
          output;
          leave;
      end;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you want to output the data for each match remove the LEAVE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 21:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235561#M55101</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-11-19T21:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235566#M55102</link>
      <description>&lt;P&gt;With only 6 variables to worry about, it's borderline whether you would want to bother with arrays.&amp;nbsp; You could code it simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;n_493 = (dx5 =: '493') + (dx6 =: '493') + (dx7 =: '493') + (dx8 =: '493') + (dx9 =: '493') + (dx10 =: '493');&lt;/P&gt;
&lt;P&gt;if n_493 &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Who knows, you might even find that the variable n_493 is useful later.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 21:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235566#M55102</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-19T21:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235572#M55104</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input (dx1 dx2 dx3 dx4 dx5 dx6 dx7 dx8 dx9 dx10)(:$5.);&lt;BR /&gt;cards;&lt;BR /&gt;22 33 44 55 4830 4931 77 88 99 500&lt;BR /&gt;; &lt;BR /&gt;proc print;&lt;BR /&gt;data test_dxcheck; &lt;BR /&gt;set have;&lt;BR /&gt;array dx $5. DX1 - DX10;&lt;BR /&gt;do i= 5 to 10;&lt;BR /&gt; if dx{i}=: '493' then output;&lt;BR /&gt;end;&lt;BR /&gt;proc print; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 21:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235572#M55104</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2015-11-19T21:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235573#M55105</link>
      <description>&lt;P&gt;If I understand you correctly, you could try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_dxcheck;
set have;
length flag $100;
retain flag;
array dx DX5-DX9;
do i=1 to dim(dx);
  if dx(i)=:'493' then flag=catx(' ',flag,vname(dx(i)));
end;
drop i;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Nov 2015 22:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235573#M55105</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-11-19T22:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: output from array do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235574#M55106</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;Thank you!&amp;nbsp;&amp;nbsp; Just needed to output the observation &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;</description>
      <pubDate>Thu, 19 Nov 2015 22:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/output-from-array-do-loop/m-p/235574#M55106</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2015-11-19T22:09:55Z</dc:date>
    </item>
  </channel>
</rss>

