<?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 statement to case statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154263#M30258</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi this will give you the desired output as stated in above comment:&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table test as select *,&lt;/P&gt;&lt;P&gt;%do i=1 %to 6;&lt;/P&gt;&lt;P&gt;%if &amp;amp;i&amp;lt;6 %then %do;&lt;/P&gt;&lt;P&gt;case when table1.num_var&amp;amp;i not in (4,5) or table1.charvar&amp;amp;i in (select table2.char_var from table2) then 1 else 0 end as flag&amp;amp;i,&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;i=6 %then %do;&lt;/P&gt;&lt;P&gt;case when table1.num_var&amp;amp;i not in (4,5) or table1.charvar&amp;amp;i in (select table2.char_var from table2) then 1 else 0 end as flag&amp;amp;i&lt;/P&gt;&lt;P&gt;%end; %end;&lt;/P&gt;&lt;P&gt;from table1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;approach 2: static code:&lt;/P&gt;&lt;P&gt;proc sql ; &lt;/P&gt;&lt;P&gt;create table test as select *,&lt;/P&gt;&lt;P&gt;case when table1.num_var1 not in (4,5) or table1.charvar1 in (select table2.char_var from table2) then 1 else 0 end as flag1,&lt;/P&gt;&lt;P&gt;case when table1.num_var2 not in (4,5) or table1.charvar2 in (select table2.char_var from table2) then 1 else 0 end as flag2,&lt;/P&gt;&lt;P&gt;case when table1.num_var3 not in (4,5) or table1.charvar3 in (select table2.char_var from table2) then 1 else 0 end as flag3,&lt;/P&gt;&lt;P&gt;case when table1.num_var4 not in (4,5) or table1.charvar4 in (select table2.char_var from table2) then 1 else 0 end as flag4,&lt;/P&gt;&lt;P&gt;case when table1.num_var5 not in (4,5) or table1.charvar5 in (select table2.char_var from table2) then 1 else 0 end as flag5,&lt;/P&gt;&lt;P&gt;case when table1.num_var6 not in (4,5) or table1.charvar6 in (select table2.char_var from table2) then 1 else 0 end as flag6&lt;/P&gt;&lt;P&gt;from table1; &lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Mar 2014 17:33:05 GMT</pubDate>
    <dc:creator>pradeepalankar</dc:creator>
    <dc:date>2014-03-24T17:33:05Z</dc:date>
    <item>
      <title>If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154256#M30251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two tables. My table 1 consists of following&amp;nbsp; numeric variables&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;num_var1, num_var2, num_var3, num_var4, num_var5, num_var6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; and following&amp;nbsp; character variables &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;charvar1,charvar2,charvar3,charvar4,charvar5,charvar6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table 2 has only one variable char_var&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and I have following code which I need to convert to Proc SQL code since I have to use it in SAS DI Studio. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if table1.num_varn not in (4,5) or table2.charvarn in &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(table2.char_var) then Table1.flagn = 0;else table1.flagn = 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note :&amp;nbsp; &lt;/STRONG&gt;In above code n has values from 1 to 6&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But somehow I am unable to crack the correct logic. Any help is really appreciated. Many thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 09:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154256#M30251</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2014-03-24T09:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154257#M30252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you know about case syntax?&lt;/P&gt;&lt;P&gt;You example is pretty straight forward, replace if with &lt;EM&gt;case when&lt;/EM&gt;, replace assignment statements with just the result, remove all ; and end it with a &lt;EM&gt;end as flagn&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Allthough, I'm not sure how you expect the part "table2.charvarn in (table2.char_var)" should work...?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 09:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154257#M30252</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-03-24T09:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154258#M30253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Linus,&lt;/P&gt;&lt;P&gt;I know about case. And&amp;nbsp; I am stuck exactly at place what you have mentioned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;part "table2.charvarn in (table2.char_var)"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;My question is there is no joining condition mentioned so how can we get values from other table without joining condition in proc sql . All i want is just get char value from table1 and if its present in table2 then create new variable flag1 in table . &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 10:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154258#M30253</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2014-03-24T10:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154259#M30254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;shouldn't it be "&lt;STRONG&gt;table1.charvarn in (table2.char_var)"&lt;/STRONG&gt; in place of "&lt;STRONG&gt;table2.charvarn in (table2.char_var)"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;as charvar1-charvar6 are present in table1 not in table2 as per your comments in post??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 10:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154259#M30254</guid>
      <dc:creator>pradeepalankar</dc:creator>
      <dc:date>2014-03-24T10:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154260#M30255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By just showing the logic for this assignment, it's hard to tell how the whole query should look like.&lt;/P&gt;&lt;P&gt;A sub-query could (perhaps) solve you problem, depending on what you want to achieve, but still, both columns are in table2, or is it a typo?&lt;/P&gt;&lt;P&gt;Perhaps it's time for you to present some sample input and desired output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 11:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154260#M30255</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-03-24T11:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154261#M30256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes You are right&lt;/P&gt;&lt;P&gt;Here is my input &lt;STRONG&gt;table 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 772px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="64"&gt;&lt;STRONG&gt;num_var1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="68"&gt;&lt;STRONG&gt;num_var6&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar6&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;7&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;n&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;p&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;j&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;o&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;z&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;s&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;e&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;y&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;t&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;f&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;m&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;x&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;r&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;r&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;7&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;k&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;l&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;e&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;j&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;z&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here is my input table 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 64px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="64"&gt;&lt;STRONG&gt;char_var&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: none;"&gt;a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: none;"&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: none;"&gt;c&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" style="border-top: none;"&gt;d&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So after execution my table 1 should look like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 1156px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="64"&gt;&lt;STRONG&gt;num_var1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;num_var5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="68"&gt;&lt;STRONG&gt;num_var6&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;charvar6&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="64"&gt;&lt;STRONG&gt;Flag6&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;7&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;n&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;p&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;j&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;o&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;x&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;z&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;s&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;c&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;b&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;e&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;y&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;t&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;d&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;y&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;f&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;m&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;x&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;r&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;r&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;7&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;k&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;l&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;a&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;e&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;j&lt;/TD&gt;&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;z&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Need help in solving this. Can subquery work over here ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 16:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154261#M30256</guid>
      <dc:creator>forumsguy</dc:creator>
      <dc:date>2014-03-24T16:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154262#M30257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are some inconsistencies with your output table versus the logic. You might want to review both. Examples of it would be row1 flag1 num_var1 is not in (4,5) which makes the condition &lt;STRONG&gt;if table1.num_varn not in (4,5) or table2.charvarn in&amp;nbsp; &lt;/STRONG&gt;&lt;STRONG&gt;(table2.char_var)&lt;/STRONG&gt; as true and thus the flag should be 0, not 1. My first guess was that you should've had an AND instead of an OR between the two conditions. However, this was also rejected by row2/flag4 because this would evaluate to true even if the OR had been replaced by an AND.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, I can still provide conceptual grounds for you to work with. The concept of "... in table2.char_var" can be achieved through the use of subquerries as pointed out above. The SQL syntax looks like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;table1.charvarn in (select char_var from table2)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This turns the subquerry in parenthesis as a list of values for the in operator. That is, it's as though the subquerry in the parenthesis resolves to ('a', 'b', 'c', 'd') from the example data above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 16:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154262#M30257</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2014-03-24T16:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement to case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154263#M30258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi this will give you the desired output as stated in above comment:&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table test as select *,&lt;/P&gt;&lt;P&gt;%do i=1 %to 6;&lt;/P&gt;&lt;P&gt;%if &amp;amp;i&amp;lt;6 %then %do;&lt;/P&gt;&lt;P&gt;case when table1.num_var&amp;amp;i not in (4,5) or table1.charvar&amp;amp;i in (select table2.char_var from table2) then 1 else 0 end as flag&amp;amp;i,&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;i=6 %then %do;&lt;/P&gt;&lt;P&gt;case when table1.num_var&amp;amp;i not in (4,5) or table1.charvar&amp;amp;i in (select table2.char_var from table2) then 1 else 0 end as flag&amp;amp;i&lt;/P&gt;&lt;P&gt;%end; %end;&lt;/P&gt;&lt;P&gt;from table1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;approach 2: static code:&lt;/P&gt;&lt;P&gt;proc sql ; &lt;/P&gt;&lt;P&gt;create table test as select *,&lt;/P&gt;&lt;P&gt;case when table1.num_var1 not in (4,5) or table1.charvar1 in (select table2.char_var from table2) then 1 else 0 end as flag1,&lt;/P&gt;&lt;P&gt;case when table1.num_var2 not in (4,5) or table1.charvar2 in (select table2.char_var from table2) then 1 else 0 end as flag2,&lt;/P&gt;&lt;P&gt;case when table1.num_var3 not in (4,5) or table1.charvar3 in (select table2.char_var from table2) then 1 else 0 end as flag3,&lt;/P&gt;&lt;P&gt;case when table1.num_var4 not in (4,5) or table1.charvar4 in (select table2.char_var from table2) then 1 else 0 end as flag4,&lt;/P&gt;&lt;P&gt;case when table1.num_var5 not in (4,5) or table1.charvar5 in (select table2.char_var from table2) then 1 else 0 end as flag5,&lt;/P&gt;&lt;P&gt;case when table1.num_var6 not in (4,5) or table1.charvar6 in (select table2.char_var from table2) then 1 else 0 end as flag6&lt;/P&gt;&lt;P&gt;from table1; &lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 17:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement-to-case-statement/m-p/154263#M30258</guid>
      <dc:creator>pradeepalankar</dc:creator>
      <dc:date>2014-03-24T17:33:05Z</dc:date>
    </item>
  </channel>
</rss>

