<?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: How can I replace a long IF/THEN or CASE statement with many OR's?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620497#M182340</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268542"&gt;@GBL__&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable lists or arrays, which could make this definition more concise, are not available in PROC SQL. Here are three options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 1:&lt;/U&gt; Use a DATA step, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array remark_code[10];
if administrative_status in ('BK', '13') or 'BK' in remark_code
  then legal_indicator_c='BK';
  else legal_indicator_c=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 2:&lt;/U&gt; Create the repetitive code with a DATA or PROC SQL step. In your example (with only 10 repetitions) the resulting code will not be (much) shorter, though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 3:&lt;/U&gt; Consider transposing your data to obtain a "long" data structure where the 10 values of &lt;FONT face="courier new,courier"&gt;remark_code1-remark_code10&lt;/FONT&gt; would be stored in 10 observations of a single variable &lt;FONT face="courier new,courier"&gt;remark_code&lt;/FONT&gt;. This structure would be more suitable for PROC SQL as you could apply summary functions together with a GROUP BY clause (grouping those 10 observations).&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 14:01:49 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-01-28T14:01:49Z</dc:date>
    <item>
      <title>How can I replace a long IF/THEN or CASE statement with many OR's??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620479#M182329</link>
      <description>&lt;P&gt;Good Morning!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am struggling to find a solution to create a more concise definition for a created variable.&amp;nbsp; As of now, am I using the below CASE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CASE
    WHEN administrative_status IN ("BK", "13") OR remark_code1 = "BK" OR remark_code2 = "BK" OR remark_code3 = "BK" OR remark_code4 = "BK OR &lt;BR /&gt;    remark_code5 = "BK" OR remark_code6 = "BK" OR remark_code7 = "BK" OR remark_code8 = "BK" OR remark_code9 = "BK" OR remark_code10 = "BK" THEN "BK"
    ELSE ""&lt;BR /&gt;END AS LEGAL_INDICATOR_c ,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;INDEXC will not work because there are multiple codes with 'B' or 'K' characters, and INDEXW can only search one variable at a time.&amp;nbsp; I am sure there is an easy solution that I am missing (I mean, there has to be, right??).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that this is INCORRECT usage but something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FIND("BK", remark_code1, remark_code2, remark_code3, remark_code4, remark_code5, remark_code6, remark_code7, remark_code8, remark_code9, remark_code10)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help!&amp;nbsp; Any feedback is appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 13:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620479#M182329</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2020-01-28T13:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can I replace a long IF/THEN or CASE statement with many OR's??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620484#M182335</link>
      <description>&lt;P&gt;Maybe something like this will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when indexw(catx(' ',administrative_status,of remark_code1-remark_code10),'BK') or administrative_status='13' then 'BK' 
  else '' 
end as legal_indicator_c&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 13:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620484#M182335</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-01-28T13:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I replace a long IF/THEN or CASE statement with many OR's??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620497#M182340</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268542"&gt;@GBL__&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable lists or arrays, which could make this definition more concise, are not available in PROC SQL. Here are three options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 1:&lt;/U&gt; Use a DATA step, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array remark_code[10];
if administrative_status in ('BK', '13') or 'BK' in remark_code
  then legal_indicator_c='BK';
  else legal_indicator_c=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 2:&lt;/U&gt; Create the repetitive code with a DATA or PROC SQL step. In your example (with only 10 repetitions) the resulting code will not be (much) shorter, though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Option 3:&lt;/U&gt; Consider transposing your data to obtain a "long" data structure where the 10 values of &lt;FONT face="courier new,courier"&gt;remark_code1-remark_code10&lt;/FONT&gt; would be stored in 10 observations of a single variable &lt;FONT face="courier new,courier"&gt;remark_code&lt;/FONT&gt;. This structure would be more suitable for PROC SQL as you could apply summary functions together with a GROUP BY clause (grouping those 10 observations).&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 14:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620497#M182340</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-28T14:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I replace a long IF/THEN or CASE statement with many OR's??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620501#M182341</link>
      <description>&lt;P&gt;For that specific test the WHICHC() function could be useful.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if whichc('BK',of administrative_status remark_code1-remark_code10)
or administrative_status = "13" then LEGAL_INDICATOR_C = 'BK';
else LEGAL_INDICATOR_C = '  ';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that it is a little harder if you are required to use SQL since SAS does not support variable lists in SQL code. You will have to list all 10 of the remark_code variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CASE
    WHEN administrative_status = "13" then 'BK'
    WHEN whichc('BK',administrative_status,remark_code1,remark_code2,remark_code3
               ,remark_code4,remark_code5,remark_code6,remark_code7,remark_code8
               ,remark_code9,remark_code10) then 'BK'
    ELSE '  '
END AS LEGAL_INDICATOR_C&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 14:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620501#M182341</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-28T14:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I replace a long IF/THEN or CASE statement with many OR's??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620821#M182479</link>
      <description>I thought it might be something via WHICHC or CHOOSEC, but wasn't sure how to implement either.  Thank you for your help!!</description>
      <pubDate>Wed, 29 Jan 2020 14:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-replace-a-long-IF-THEN-or-CASE-statement-with-many-OR/m-p/620821#M182479</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2020-01-29T14:52:11Z</dc:date>
    </item>
  </channel>
</rss>

