<?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 'if then delete' statement after multiple arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857810#M338950</link>
    <description>&lt;P&gt;You have not shown us a portion of your data, so we can not be sure what is happening. Your explanation also doesn't indicate what result is desired, nor is this a helpful description that we can work from: "&lt;SPAN&gt;it's almost as if everything is being overwritten".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please provide a portion of your data as working SAS data step code, which you can type yourself, or by following these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;. Do not attach files or provide screen captures.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Please explain clearly what you expect to happen on this sample data.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2023 18:34:26 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-02-08T18:34:26Z</dc:date>
    <item>
      <title>using 'if then delete' statement after multiple arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857809#M338949</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm unable to get SAS to return observations when using an 'if' statement including 3 new variables I've made using multiple arrays. The first code (below) works fine and returns ~230 observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA LIB.DAD05;&lt;BR /&gt;SET DAD.DAD2005;&lt;BR /&gt;ARRAY DX (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO i = 1 TO 25;&lt;BR /&gt;IF DX(i) =: 'X47' OR DX(i)=: 'X470' OR DX(i)=: 'X471' OR DX(i)=: 'X472' OR DX(i)=: 'X473' OR DX(i)=: 'X474' THEN UNINTENTIONAL_POISONING=1;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when I use multiple arrays and an 'if' statement with the 3 new variables (below), it's almost as if everything is being overwritten (I suspect that the final array should return 0 observations, just due to dataset variable issues, but the first array has already returned ~230 observations when run on its own).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA LIB.DAD05;&lt;BR /&gt;SET DAD.DAD2005;&lt;BR /&gt;ARRAY DX (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO i = 1 TO 25;&lt;BR /&gt;IF DX(i) =: 'X47' OR DX(i)=: 'X470' OR DX(i)=: 'X471' OR DX(i)=: 'X472' OR DX(i)=: 'X473' OR DX(i)=: 'X474' THEN UNINTENTIONAL_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;ARRAY DXA (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO j = 1 TO 25;&lt;BR /&gt;IF DXA(j) =: 'T58' THEN CO_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;ARRAY DXB (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO k = 1 TO 25;&lt;BR /&gt;IF DXB(k) =: 'Y17' OR DXB(k)=: 'Y170' OR DXB(k)=: 'Y171' OR DXB(k)=: 'Y172' OR DXB(k)=: 'Y173' OR DXB(k)=: 'Y174' &lt;BR /&gt;THEN UNDETERMINED_INTENT_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;IF UNINTENTIONAL_POISONING NE 1 OR CO_POISONING NE 1 OR UNDETERMINED_INTENT_POISONING NE 1 THEN DELETE;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, thank you - this community is great.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857809#M338949</guid>
      <dc:creator>Angmar</dc:creator>
      <dc:date>2023-02-08T18:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: using 'if then delete' statement after multiple arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857810#M338950</link>
      <description>&lt;P&gt;You have not shown us a portion of your data, so we can not be sure what is happening. Your explanation also doesn't indicate what result is desired, nor is this a helpful description that we can work from: "&lt;SPAN&gt;it's almost as if everything is being overwritten".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please provide a portion of your data as working SAS data step code, which you can type yourself, or by following these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;. Do not attach files or provide screen captures.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Please explain clearly what you expect to happen on this sample data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857810#M338950</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-08T18:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: using 'if then delete' statement after multiple arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857814#M338951</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA LIB.DAD05;
SET DAD.DAD2005;
ARRAY DX (25) DIAG_CODE_1-DIAG_CODE_25 ;
DO i = 1 TO 25;
     IF DX(i) in: ( 'X47', 'X470', 'X471',  'X472',  'X473',  'X474') THEN UNINTENTIONAL_POISONING=1;
    IF DX(j) =: 'T58' THEN CO_POISONING=1;
    IF DX(k) =: 'Y17' OR DX(k)=: 'Y170' OR DX(k)=: 'Y171' OR DX(k)=: 'Y172' OR DX(k)=: 'Y173' OR DX(k)=: 'Y174'
THEN UNDETERMINED_INTENT_POISONING=1;
END;

IF sum(UNINTENTIONAL_POISONING, CO_POISONING, UNDETERMINED_INTENT_POISONING) =0 THEN DELETE;


RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Don't declare the same array multiple times&lt;/LI&gt;
&lt;LI&gt;Don't loop through same array multiple times&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Don't use OR when you can use IN: or IN&lt;/LI&gt;
&lt;LI&gt;Show an example with data of what isn't meeting expectations.&lt;/LI&gt;
&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197740"&gt;@Angmar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm unable to get SAS to return observations when using an 'if' statement including 3 new variables I've made using multiple arrays. The first code (below) works fine and returns ~230 observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA LIB.DAD05;&lt;BR /&gt;SET DAD.DAD2005;&lt;BR /&gt;ARRAY DX (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO i = 1 TO 25;&lt;BR /&gt;IF DX(i) =: 'X47' OR DX(i)=: 'X470' OR DX(i)=: 'X471' OR DX(i)=: 'X472' OR DX(i)=: 'X473' OR DX(i)=: 'X474' THEN UNINTENTIONAL_POISONING=1;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when I use multiple arrays and an 'if' statement with the 3 new variables (below), it's almost as if everything is being overwritten (I suspect that the final array should return 0 observations, just due to dataset variable issues, but the first array has already returned ~230 observations when run on its own).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA LIB.DAD05;&lt;BR /&gt;SET DAD.DAD2005;&lt;BR /&gt;ARRAY DX (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO i = 1 TO 25;&lt;BR /&gt;IF DX(i) =: 'X47' OR DX(i)=: 'X470' OR DX(i)=: 'X471' OR DX(i)=: 'X472' OR DX(i)=: 'X473' OR DX(i)=: 'X474' THEN UNINTENTIONAL_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;ARRAY DXA (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO j = 1 TO 25;&lt;BR /&gt;IF DXA(j) =: 'T58' THEN CO_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;ARRAY DXB (25) DIAG_CODE_1-DIAG_CODE_25 ;&lt;BR /&gt;DO k = 1 TO 25;&lt;BR /&gt;IF DXB(k) =: 'Y17' OR DXB(k)=: 'Y170' OR DXB(k)=: 'Y171' OR DXB(k)=: 'Y172' OR DXB(k)=: 'Y173' OR DXB(k)=: 'Y174' &lt;BR /&gt;THEN UNDETERMINED_INTENT_POISONING=1;&lt;BR /&gt;END;&lt;/P&gt;
&lt;P&gt;IF UNINTENTIONAL_POISONING NE 1 OR CO_POISONING NE 1 OR UNDETERMINED_INTENT_POISONING NE 1 THEN DELETE;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, thank you - this community is great.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857814#M338951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-08T18:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: using 'if then delete' statement after multiple arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857815#M338952</link>
      <description>&lt;P&gt;An array addresses variables. If all the variables are the same then use one array. There is no reason to have multiple arrays for the same variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you do not assign any values to those 3 variables for what I suspect are most of the records then they are MISSING values and hence "ne 1".&lt;/P&gt;
&lt;P&gt;It would help to describe what you think you want for the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read this example data and determine which records you expect in the output. &lt;STRONG&gt;THEN&lt;/STRONG&gt; run the data step and see if it matches your expectation.&lt;/P&gt;
&lt;PRE&gt;data junk;
  input val1 val2;
  if val1 ne 1 or val2 ne 1 then delete;
datalines;
1 .
. 1
1 1
. .
;
&lt;/PRE&gt;
&lt;P&gt;(Hint: if you expect 3 records in the output the If statement is incorrect)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857815#M338952</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T18:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: using 'if then delete' statement after multiple arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857940#M338985</link>
      <description>&lt;P&gt;First of all, there's no need to shout at the SAS interpreter. It works very fine with lowercase, which is easier to read.&lt;/P&gt;
&lt;P&gt;Second, you define three array fior the same variables; this is not necessary, you can reuse an array as often as you want.&lt;/P&gt;
&lt;P&gt;Third, you can do everything in one DO loop.&lt;/P&gt;
&lt;P&gt;Fourth, your code will only output observations with no poisoning at all. Is this what you want, or do you want all observations where&amp;nbsp;&lt;EM&gt;any&lt;/EM&gt; poisoning is detected?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib.dad05;
set dad.dad2005;
array dx{25} diag_code_1-diag_code25;
do i =1 to 25;
  if dx{i} =: 'X47' or dx(i)=: 'X470' or dx(i)=: 'X471' or dx(i)=: 'X472' or dx(i)=: 'X473' or dx(i)=: 'X474' then unintentional_poisoning = 1;
  if dx(i) =: 'T58' then co_poisoning = 1;
  if dx(k) =: 'Y17' or dx(k)=: 'Y170' or dx(k)=: 'Y171' or dx(k)=: 'Y172' or dx(k)=: 'Y173' or dx(k)=: 'Y174' then undetermined_intent_poisoning = 1;
end;
if sum(unintentional_poisoning,co_poisoning,undetermined_intent_poisoning) le 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 06:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-if-then-delete-statement-after-multiple-arrays/m-p/857940#M338985</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-09T06:29:40Z</dc:date>
    </item>
  </channel>
</rss>

