<?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 arrays with hospital discharge data/ duplicate output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264933#M52027</link>
    <description>&lt;P&gt;I don't have any of your data to test but that is the purpose of LEAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: To make your code a little easier to maintain you should consider using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;dim(dx)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Next time when they add or remove variables of interest then you only need to change the Array definition. Otherwise if you forget to change the 29 to 31 or 26 you either miss comparisons or get an array index out of range error at run time.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2016 22:33:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-04-19T22:33:05Z</dc:date>
    <item>
      <title>Using arrays with hospital discharge data/ duplicate output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264871#M52015</link>
      <description>&lt;P&gt;Still new to writing arrays. &amp;nbsp;Looking to extract any records from a larger outpatient emergency discharge file 'entireEDdataset', to a new dataset 'hypertension',&amp;nbsp;where&amp;nbsp;&lt;U&gt;any&lt;/U&gt; of the discharge diagnoses (principal or 28 secondary) are listed as the ICD-9 codes for hypertension. &amp;nbsp;The program below runs; however, I end up with duplicate observations for those records where the criteria is met more than once (example B and D below - duplicates record count = number of times the criteria was met). &amp;nbsp;How do I get the array to stop outputting once the criteria is met the first time? &amp;nbsp;Running Base SAS 9.3&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Input Dataset 'EntireEDDataset':&lt;/STRONG&gt;&lt;BR /&gt;ID&lt;/U&gt; &lt;U&gt;principaldx&lt;/U&gt; &lt;U&gt;diag1&lt;/U&gt; &lt;U&gt;diag2&lt;/U&gt; &lt;U&gt;diag3&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[...] &lt;U&gt;diag28&lt;/U&gt; [...other vars...]&lt;BR /&gt;A 401.00 &amp;nbsp; &amp;nbsp; &amp;nbsp; 123.91 656.00 789.10 &amp;nbsp; &amp;nbsp; &amp;nbsp;567.00&lt;BR /&gt;B 402.00 &amp;nbsp; &amp;nbsp; &amp;nbsp; 403.00 123.40 234.50 &amp;nbsp; &amp;nbsp; 999.09&lt;BR /&gt;C 123.45 &amp;nbsp; &amp;nbsp; &amp;nbsp; 678.91 546.20 698.20 &amp;nbsp; &amp;nbsp; 546.80&lt;BR /&gt;D 403.00 &amp;nbsp; &amp;nbsp; &amp;nbsp; 402.00 401.00 405.00 &amp;nbsp; &amp;nbsp; &amp;nbsp; 123.45&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hypertension;
set entireEDdataset;
array dx [29] principaldx diag1-diag28;
     do i = 1 to 29;
           if dx(i) in : ('401', '402', '403', '404', '405') then output hypertension;
     end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dataset 'HYPERTENSION':
A, 401.00, 123.91, 656.00, 789.10, [...], 567.00 [...other vars...]
B, 402.00, 403.00, 123.40, 234.50, [...], 999.09 [...other vars...]
B, 402.00, 403.00, 123.40, 234.50, [...], 999.09 [...other vars...]
D, 403.00, 402.00, 401.00, 405.00, [...], 123.45 [...other vars...]
D, 403.00, 402.00, 401.00, 405.00, [...], 123.45 [...other vars...]
D, 403.00, 402.00, 401.00, 405.00, [...], 123.45 [...other vars...]
D, 403.00, 402.00, 401.00, 405.00, [...], 123.45&amp;nbsp;[...other vars...]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 19:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264871#M52015</guid>
      <dc:creator>cgray</dc:creator>
      <dc:date>2016-04-19T19:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays with hospital discharge data/ duplicate output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264881#M52017</link>
      <description>&lt;P&gt;This will stop evaluating the IF the first time it finds a match and exit the Do loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hypertension;
set entireEDdataset;
array dx [29] principaldx diag1-diag28;
     do i = 1 to 29;
           if dx(i) in : ('401', '402', '403', '404', '405') then do;
               output hypertension;
               leave;
           end;
     end;
drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2016 19:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264881#M52017</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-19T19:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays with hospital discharge data/ duplicate output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264883#M52019</link>
      <description>&lt;P&gt;Thank you so much. &amp;nbsp;Unfamilar with the leave statement - so, if the condition for i = 1 is met then the internal do loop activates ("then do") and outputs to hypertension; the leave statement then sends it back up to the external/first do loop to start i=2and so forth?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 19:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264883#M52019</guid>
      <dc:creator>cgray</dc:creator>
      <dc:date>2016-04-19T19:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays with hospital discharge data/ duplicate output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264933#M52027</link>
      <description>&lt;P&gt;I don't have any of your data to test but that is the purpose of LEAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: To make your code a little easier to maintain you should consider using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;dim(dx)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Next time when they add or remove variables of interest then you only need to change the Array definition. Otherwise if you forget to change the 29 to 31 or 26 you either miss comparisons or get an array index out of range error at run time.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-with-hospital-discharge-data-duplicate-output/m-p/264933#M52027</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-19T22:33:05Z</dc:date>
    </item>
  </channel>
</rss>

