<?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: if then esle delete no error but still get 0 obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929641#M365778</link>
    <description>&lt;P&gt;And an alternate approach (untested as no data available)&lt;/P&gt;
&lt;PRE&gt;data yyy;
   set xxx
   /* array to allow some shorthand code*/
   array rec (*) Deathcause_ICD condition_rec_: ;
   disease1 = ( whichc('A923' ,of rec(*) )&amp;gt;0
             or whichc('A9231',of rec(*) )&amp;gt;0
             or whichc('A9232',of rec(*) )&amp;gt;0
             or whichc('A9239',of rec(*) )&amp;gt;0
               );
   if disease1;
run;&lt;/PRE&gt;
&lt;P&gt;The WHICHC function searches for the value of the first parameter in a list of values or variables and returns the position in list if found. The Array statement is way to place all the variables to search in a shorthand version. The "of rec(*)" says use all variables in the array for the list to search. There is a companion function for numeric values WHICHN. This sort of list can be used with most functions that accept a list of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The IF keeps observations where Disease1 is 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF there are no codes that start A923 other than the 4 shown you could use the =: 'A923' to compare the variable to see if it begins with those and don't even need the list&lt;/P&gt;
&lt;PRE&gt;data YYY;
set XXX;
if DeathCause_ICD =: 'A923'
or condition_rec_1 =: 'A923'
or condition_rec_2 =: 'A923'
&amp;lt;etc&amp;gt;&lt;/PRE&gt;
&lt;P&gt;If you have other codes such as A9236 that you do want to delete then this would not be appropriate.&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2024 19:55:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-05-24T19:55:22Z</dc:date>
    <item>
      <title>if then esle delete no error but still get 0 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929635#M365774</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to filter some of my data and create a new dataset. using the following syntax:&lt;/P&gt;
&lt;P&gt;data YYY;&lt;BR /&gt;set XXX;&lt;BR /&gt;if DeathCause_ICD in ("A923", "A9231","A9232","A9239") THEN disease1=1;&lt;BR /&gt;IF condition_rec_1 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_2 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_3 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_4 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_5 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_6 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_7 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_8 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_9 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_10 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_11 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_12 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_13 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_14 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_15 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_16 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_17 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_18 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;IF condition_rec_19 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;if condition_rec_20 in ("A923", "A9231","A9232","A9239") then disease1=1;&lt;BR /&gt;else delete;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While I am not receinving any error in the log, still my syntax not working and giving me 0 observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used this syntax multiple times and i canot figure out wher it is going wront. any thoughts appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 19:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929635#M365774</guid>
      <dc:creator>raheleh22</dc:creator>
      <dc:date>2024-05-24T19:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: if then esle delete no error but still get 0 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929636#M365775</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF condition_rec_19 in ("A923", "A9231","A9232","A9239") then disease1=1;
if condition_rec_20 in ("A923", "A9231","A9232","A9239") then disease1=1;
else delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above is the portion of your code where the problem lies. On the second line above, if this fails because condition_rec_20 is not one of the four values shown, then the next line executes and deletes the record. Everything that is tested previously does not have an impact on this deletion. What I think you want is (I've left out a few lines):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data YYY;
set XXX;
if DeathCause_ICD in ("A923", "A9231","A9232","A9239") THEN disease1=1;
else IF condition_rec_1 in ("A923", "A9231","A9232","A9239") then disease1=1;
else if condition_rec_2 in ("A923", "A9231","A9232","A9239") then disease1=1;
   ....
else IF condition_rec_19 in ("A923", "A9231","A9232","A9239") then disease1=1;
else if condition_rec_20 in ("A923", "A9231","A9232","A9239") then disease1=1;
else delete;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 May 2024 19:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929636#M365775</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-24T19:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: if then esle delete no error but still get 0 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929637#M365776</link>
      <description>&lt;P&gt;Also, you can save yourself some typing and avoid possible typographic errors like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let codes="A923", "A9231","A9232","A9239";
data YYY;
set XXX;
if DeathCause_ICD in (&amp;amp;codes) 
or condition_rec_1 in (&amp;amp;codes)
or condition_rec_2 in (&amp;amp;codes)
   ....
or condition_rec_19 in (&amp;amp;codes) 
or condition_rec_20 in (&amp;amp;codes) then disease1=1;
else delete;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 May 2024 19:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929637#M365776</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-24T19:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: if then esle delete no error but still get 0 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929638#M365777</link>
      <description>&lt;P&gt;yes, the esle if statement did work. thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 19:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929638#M365777</guid>
      <dc:creator>raheleh22</dc:creator>
      <dc:date>2024-05-24T19:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: if then esle delete no error but still get 0 obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929641#M365778</link>
      <description>&lt;P&gt;And an alternate approach (untested as no data available)&lt;/P&gt;
&lt;PRE&gt;data yyy;
   set xxx
   /* array to allow some shorthand code*/
   array rec (*) Deathcause_ICD condition_rec_: ;
   disease1 = ( whichc('A923' ,of rec(*) )&amp;gt;0
             or whichc('A9231',of rec(*) )&amp;gt;0
             or whichc('A9232',of rec(*) )&amp;gt;0
             or whichc('A9239',of rec(*) )&amp;gt;0
               );
   if disease1;
run;&lt;/PRE&gt;
&lt;P&gt;The WHICHC function searches for the value of the first parameter in a list of values or variables and returns the position in list if found. The Array statement is way to place all the variables to search in a shorthand version. The "of rec(*)" says use all variables in the array for the list to search. There is a companion function for numeric values WHICHN. This sort of list can be used with most functions that accept a list of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The IF keeps observations where Disease1 is 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF there are no codes that start A923 other than the 4 shown you could use the =: 'A923' to compare the variable to see if it begins with those and don't even need the list&lt;/P&gt;
&lt;PRE&gt;data YYY;
set XXX;
if DeathCause_ICD =: 'A923'
or condition_rec_1 =: 'A923'
or condition_rec_2 =: 'A923'
&amp;lt;etc&amp;gt;&lt;/PRE&gt;
&lt;P&gt;If you have other codes such as A9236 that you do want to delete then this would not be appropriate.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 19:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-esle-delete-no-error-but-still-get-0-obs/m-p/929641#M365778</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-24T19:55:22Z</dc:date>
    </item>
  </channel>
</rss>

