<?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: Shortened if then statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710207#M218582</link>
    <description>&lt;P&gt;You could use the &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0jfvenvsqk24vn1q2ypospoq9ij.htm&amp;amp;locale=en" target="_self"&gt;WHICHC function&lt;/A&gt;. Example given at the link.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jan 2021 16:17:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-01-08T16:17:41Z</dc:date>
    <item>
      <title>Shortened if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710201#M218576</link>
      <description>&lt;P&gt;Hello SAS Community!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping someone might have a trick to shorten the following if then statement. I am working in a file that contains 44 diagnosis codes, I need to go through those and make some of the diagnosis codes a new variable with the specific diagnosis (for example femoral neck fracture = yes1/no0), but am not interested in all of the diagnosis codes (there are over 5k) so I don't want to transpose the variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have been doing is as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data.x; set.x;&lt;/P&gt;&lt;P&gt;if diagcode1 = 'S72.0' then femoralneckfx = 1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if diagcode2 = 'S72.0' then femoralneckfx = 1;&lt;/P&gt;&lt;P&gt;....(and so on for all 44 diagnosis codes)....&lt;/P&gt;&lt;P&gt;if femoralneckfx NE 1 then femoralneckfx = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then repeating for a similar process for the 9 diagnoses of interest.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found I could slightly shorten it a little&amp;nbsp; by typing&amp;nbsp;"if diagcode1 = 'S72.0' or diagcode2 = 'S72.0' of diagcode3 = 'S72.0' .......then femoralneckfx = 1;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I was wondering if there is a way to write it even shorter, can you look for the text across all 44 variables at the same time so you don't have to repeat the ='S72.0'?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried " if 'S72.0' in (diagcode1, diagcode2, diagcode3...) then femoralneckfx = 1; " but that didn't work either.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help you can provide!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steph&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 16:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710201#M218576</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2021-01-08T16:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shortened if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710207#M218582</link>
      <description>&lt;P&gt;You could use the &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0jfvenvsqk24vn1q2ypospoq9ij.htm&amp;amp;locale=en" target="_self"&gt;WHICHC function&lt;/A&gt;. Example given at the link.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 16:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710207#M218582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-08T16:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Shortened if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710233#M218598</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x1;
    set x;
    femoralneckfx=whichc('S72.0',of diagcode:)&amp;gt;0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2021 17:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710233#M218598</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-08T17:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Shortened if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710307#M218629</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried " if 'S72.0' in (diagcode1, diagcode2, diagcode3...) then femoralneckfx = 1; " but that didn't work either.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The correct syntax for this type of condition is: &lt;FONT face="courier new,courier"&gt;&lt;EM&gt;value&lt;/EM&gt; IN &lt;STRONG&gt;&lt;EM&gt;arrayname&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array diagcode[44];
femoralneckfx=('S72.0' in diagcode);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The necessary ARRAY statement could also refer to the variable list &lt;FONT face="courier new,courier"&gt;diagcode:&lt;/FONT&gt;, assuming that &lt;FONT face="courier new,courier"&gt;diagcode1&lt;/FONT&gt; through &lt;FONT face="courier new,courier"&gt;diagcode44&lt;/FONT&gt; are the only variables in the input dataset (HAVE) whose names start with "diagcode". Then the array name doesn't need to be &lt;FONT face="courier new,courier"&gt;diagcode&lt;/FONT&gt;&amp;nbsp;and also the hardcoded "&lt;FONT face="courier new,courier"&gt;44&lt;/FONT&gt;" can be eliminated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array _dc[*] diagcode:;
femoralneckfx=('S72.0' in _dc);
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2021 21:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Shortened-if-then-statement/m-p/710307#M218629</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-08T21:50:21Z</dc:date>
    </item>
  </channel>
</rss>

