<?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: do loops in arrays outputting multiple observations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loops-in-arrays-outputting-multiple-observations/m-p/620574#M182370</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197740"&gt;@Angmar&lt;/a&gt;: You need to break out of the loop once the diagnosis searched for has been found:&lt;/P&gt;
&lt;PRE&gt;data lib.nbhr05 (drop = i) ;                                                                                                                                                                                                                                    
  set red.red05 (where=(city='3')) ;                                                                                                                                                                                                                            
  array diag [25] diag_code_1-diag_code_25 ;                                                                                                                                                                                                                    
  do i = 1 to dim (diag) ;                                                                                                                                                                                                                                      
    if diag[i] in: ("T67", "R55") then do ;                                                                                                                                                                                                                     
      output ;                                                                                                                                                                                                                                                  
      leave ;                                                                                                                                                                                                                                                   
    end ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
run ;        
&lt;/PRE&gt;
&lt;P&gt;However, the fact is that you don't need any looping at all:&lt;/P&gt;
&lt;PRE&gt;data lib.nbhr05 ;                                                                                                                                                                                                                                    
  set red.red05 (where=(city='3')) ;                                                                                                                                                                                                                            
  array diag [25] diag_code_1-diag_code_25 ;                                                                                                                                                                                                                    
  if "T67" in diag or "R55" in diag ;                                                                                                                                                                                                                           
run ; 
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 17:29:09 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2020-01-28T17:29:09Z</dc:date>
    <item>
      <title>do loops in arrays outputting multiple observations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loops-in-arrays-outputting-multiple-observations/m-p/620561#M182363</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I've been using the code below to identify records that have one or both diagnoses (t67 or r55) and output them to LIB.NBHR05. Someone informed me that my code would output the same observations multiple times, so I wouldn't have the actual number of records with one or both diagnoses. Is there a work-around without creating a new variable?&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;26 DATA LIB.NBHR05;&lt;BR /&gt;27 SET RED.RED05 (WHERE=(CITY='3'));&lt;BR /&gt;28 ARRAY DIAGNOSIS (25) DIAG_CODE_1-DIAG_CODE_25;&lt;BR /&gt;29 DO i =1 TO 25;&lt;BR /&gt;30 IF DIAGNOSIS(i) =: 'T67' OR DIAGNOSIS(i) =: 'R55' THEN OUTPUT;&lt;BR /&gt;31 END;&lt;BR /&gt;32 RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 16:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loops-in-arrays-outputting-multiple-observations/m-p/620561#M182363</guid>
      <dc:creator>Angmar</dc:creator>
      <dc:date>2020-01-28T16:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: do loops in arrays outputting multiple observations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loops-in-arrays-outputting-multiple-observations/m-p/620574#M182370</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197740"&gt;@Angmar&lt;/a&gt;: You need to break out of the loop once the diagnosis searched for has been found:&lt;/P&gt;
&lt;PRE&gt;data lib.nbhr05 (drop = i) ;                                                                                                                                                                                                                                    
  set red.red05 (where=(city='3')) ;                                                                                                                                                                                                                            
  array diag [25] diag_code_1-diag_code_25 ;                                                                                                                                                                                                                    
  do i = 1 to dim (diag) ;                                                                                                                                                                                                                                      
    if diag[i] in: ("T67", "R55") then do ;                                                                                                                                                                                                                     
      output ;                                                                                                                                                                                                                                                  
      leave ;                                                                                                                                                                                                                                                   
    end ;                                                                                                                                                                                                                                                       
  end ;                                                                                                                                                                                                                                                         
run ;        
&lt;/PRE&gt;
&lt;P&gt;However, the fact is that you don't need any looping at all:&lt;/P&gt;
&lt;PRE&gt;data lib.nbhr05 ;                                                                                                                                                                                                                                    
  set red.red05 (where=(city='3')) ;                                                                                                                                                                                                                            
  array diag [25] diag_code_1-diag_code_25 ;                                                                                                                                                                                                                    
  if "T67" in diag or "R55" in diag ;                                                                                                                                                                                                                           
run ; 
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 17:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loops-in-arrays-outputting-multiple-observations/m-p/620574#M182370</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-28T17:29:09Z</dc:date>
    </item>
  </channel>
</rss>

