<?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 for nested case when. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629557#M77629</link>
    <description>thanks</description>
    <pubDate>Wed, 04 Mar 2020 19:01:47 GMT</pubDate>
    <dc:creator>wwwz</dc:creator>
    <dc:date>2020-03-04T19:01:47Z</dc:date>
    <item>
      <title>need help for nested case when.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629524#M77625</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table check1 as&lt;BR /&gt;select *,&lt;/P&gt;&lt;P&gt;case when new=1 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=1 then 1 else 0 end as aa1,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=2 then 1 else 0 end as aa2,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=3 then 1 else 0 end as aa3&lt;/P&gt;&lt;P&gt;end&amp;nbsp;&lt;/P&gt;&lt;P&gt;from id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the code above, it looks not right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is how I close the big loop for new=1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 18:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629524#M77625</guid>
      <dc:creator>wwwz</dc:creator>
      <dc:date>2020-03-04T18:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: need help for nested case when.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629531#M77626</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157955"&gt;@wwwz&lt;/a&gt;&amp;nbsp; Not quite suited for "nested" case when, rather it's far more convenient and precise to use AND operator like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;case when new=1 and&amp;nbsp;&amp;nbsp;aa=1 then 1 else 0 end as aa1,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when&amp;nbsp;new=1 and&amp;nbsp; aa=2 then 1 else 0 end as aa2,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when new=1 and&amp;nbsp; aa=3 then 1 else 0 end as aa3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 18:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629531#M77626</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-04T18:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: need help for nested case when.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629537#M77627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157955"&gt;@wwwz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table check1 as&lt;BR /&gt;select *,&lt;/P&gt;
&lt;P&gt;case when new=1 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=1 then 1 else 0 end as aa1,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=2 then 1 else 0 end as aa2,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; case when aa=3 then 1 else 0 end as aa3&lt;/P&gt;
&lt;P&gt;end&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote the code above, it looks not right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question is how I close the big loop for new=1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Might say this is more of a data step task:&lt;/P&gt;
&lt;PRE&gt;data check1;
  set id;
  if new=1 then do;
   aa1 = (aa=1);
   aa2 = (aa=2);
   aa3 = (aa=3);
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Especially if you have may more values to check. Consider if AA takes values of 1 to 25. That gets to be a lot of CASE coding.&lt;/P&gt;
&lt;P&gt;But with an array in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.id;
   input new aa;
datalines;
1 1
1 3
0 1
1 25
;

data work.check1;
   set work.id;
   array a(25) aa1-aa25;
   if new= 1 then do i= 1 to dim(a);
      a[i]= (aa=i);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;And ARRAYS do not work in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 18:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629537#M77627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-04T18:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: need help for nested case when.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629557#M77629</link>
      <description>thanks</description>
      <pubDate>Wed, 04 Mar 2020 19:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629557#M77629</guid>
      <dc:creator>wwwz</dc:creator>
      <dc:date>2020-03-04T19:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: need help for nested case when.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629558#M77630</link>
      <description>&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 19:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/need-help-for-nested-case-when/m-p/629558#M77630</guid>
      <dc:creator>wwwz</dc:creator>
      <dc:date>2020-03-04T19:02:03Z</dc:date>
    </item>
  </channel>
</rss>

