<?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: Need help with nested if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532850#M146048</link>
    <description>Why? Proc SQL won't perform better.</description>
    <pubDate>Tue, 05 Feb 2019 06:27:02 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-02-05T06:27:02Z</dc:date>
    <item>
      <title>Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532843#M146044</link>
      <description>&lt;P&gt;Hi There,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a code which I am trying to convert from Data step to proc sql&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if a = 0 and b = 1 and s= " " then do ;&lt;/P&gt;&lt;P&gt;r = 1 ;&lt;/P&gt;&lt;P&gt;s= 2;&lt;/P&gt;&lt;P&gt;t = 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if p = 2 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; q= 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;r= 3 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else do ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; q= 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; r = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; how can we convert this into case when ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 05:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532843#M146044</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-05T05:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532850#M146048</link>
      <description>Why? Proc SQL won't perform better.</description>
      <pubDate>Tue, 05 Feb 2019 06:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532850#M146048</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-05T06:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532851#M146049</link>
      <description>&lt;P&gt;Its a business requirement to keep the code in sync&amp;nbsp; as all other processes are using the sql&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 06:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532851#M146049</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-05T06:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532860#M146056</link>
      <description>&lt;P&gt;SQL case-when statements have the limitation that you can only assign to one variable in each statement, so it becomes a bit tedious:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 
case
  when a = 0 and b = 1 and s= " " then case
    when p=2 then 3
    else 0
    end
  else null
end as r,
case
  when a = 0 and b = 1 and s= " " then case
    when p=2 then 1
    else 0
    end
  else null
end as q,
case
  when a = 0 and b = 1 and s= " " then 2
  else null
end as s,
case
  when a = 0 and b = 1 and s= " " then 3
  else null
end as t
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There was a small glitch in your original code: First you assign the value 1 to R, then you make it 3 if P=2 and else 0. So the original assignment to 1 is never used for anything, which is why you won't see it in the code above.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 08:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532860#M146056</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-02-05T08:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532870#M146060</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Its a business requirement to keep the code in sync&amp;nbsp; as all other processes are using the sql&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's an incredibly stupid argument. You use the tools best suited for a job, period. The one that gave you this "requirement" is a clueless noob.&lt;/P&gt;
&lt;P&gt;Not using data steps when using SAS is like trying to drive a Ferrari with coal.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 09:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532870#M146060</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-05T09:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532885#M146062</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also abbreviate repetitive code to obtain a more condensed PROC SQL step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cond=case when a=0 &amp;amp; b=1 &amp;amp; s=" " then 1 else . end;

proc sql;
create table want as
select
  &amp;amp;cond*(p=2)   as q,
  &amp;amp;cond*(p=2)*3 as r,
  &amp;amp;cond*2       as s,
  &amp;amp;cond*3       as t
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Feb 2019 11:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/532885#M146062</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-05T11:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533353#M146218</link>
      <description>sorry here's my code&lt;BR /&gt;if a = "s" and m = "" and f = . then do ;&lt;BR /&gt;x = c ;&lt;BR /&gt;e = l;&lt;BR /&gt;n = 0 ;&lt;BR /&gt;if rs = 0 then do ;&lt;BR /&gt;j= 1;&lt;BR /&gt;k= 2;&lt;BR /&gt;w = 3 ;&lt;BR /&gt;end ;&lt;BR /&gt;else if o ne p then do ;&lt;BR /&gt;j=3;&lt;BR /&gt;k=4;&lt;BR /&gt;w = 3 ;&lt;BR /&gt;else do ;&lt;BR /&gt;j=0;&lt;BR /&gt;k=0;&lt;BR /&gt;d = 6;&lt;BR /&gt;r = 7 ;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Feb 2019 18:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533353#M146218</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-06T18:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533364#M146220</link>
      <description>&lt;P&gt;Since you set 13 variables, you would need 13 case/when clauses in your SQL select. Stay with the data step.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 19:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533364#M146220</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-06T19:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with nested if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533458#M146254</link>
      <description>&lt;P&gt;The argument, however stupid, is probably based&amp;nbsp;on the expectation that the business is more likely to find programmers that understand sql than the sas data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, while this may initially seem to be a reasonable notion (I'm not ready to elevate to idea status), it counters one of the best reasons for getting a sas license to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps it may seem like a good condition to set in order to later move&lt;SPAN style="text-decoration: line-through;"&gt;re&lt;/SPAN&gt; to some software environment other than SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 01:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-nested-if-statement/m-p/533458#M146254</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-07T01:53:12Z</dc:date>
    </item>
  </channel>
</rss>

