<?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: Case when in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361924#M85437</link>
    <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Desired output be like this */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;respndt Completed total_cont&lt;BR /&gt;aa 1 2&lt;BR /&gt;bb 2 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;even i tried it in sql using case when, but am not much familiar with sql its hard for me to &amp;nbsp;get the output.&lt;/P&gt;</description>
    <pubDate>Fri, 26 May 2017 11:25:44 GMT</pubDate>
    <dc:creator>sanjay1</dc:creator>
    <dc:date>2017-05-26T11:25:44Z</dc:date>
    <item>
      <title>Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361921#M85435</link>
      <description>&lt;P&gt;Hi SAS Experts&lt;BR /&gt;Here am trying get the count of names by respndt--there are two scenerios&lt;BR /&gt;1.count(names) as completed, by respndt, where completed="Yes"&lt;BR /&gt;2.count(names) as total_cont by respndt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;plese suggest a way to do this, below is my dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data abc;&lt;BR /&gt;input respndt$ name$ completed$;&lt;BR /&gt;datalines;&lt;BR /&gt;aa ksv yes&lt;BR /&gt;aa kbc no&lt;BR /&gt;bb xab no&lt;BR /&gt;bb gfg no&lt;BR /&gt;bb ghg yes&lt;BR /&gt;bb gkg yes&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankls &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Sanjay&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 10:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361921#M85435</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T10:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361923#M85436</link>
      <description>&lt;P&gt;Guessing on what you want the output to look like:&lt;BR /&gt;&amp;nbsp;Simplest way is datastep:&lt;/P&gt;
&lt;PRE&gt;data want (keep=sum1 sum2);
  set abc end=last;
  retain sum1 sum2 0;
  sum1=sum1+1;
  sum2=sum2 + ifn(completed="Yes",1,0);
  if last then output;
run;&lt;/PRE&gt;
&lt;P&gt;You can do it in SQL, however you need to provide more information. &amp;nbsp;SQL count() function is a group by, however you are not grouping by anything here, so the code would be more verbose than the datastep.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361923#M85436</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-26T11:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361924#M85437</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Desired output be like this */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;respndt Completed total_cont&lt;BR /&gt;aa 1 2&lt;BR /&gt;bb 2 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;even i tried it in sql using case when, but am not much familiar with sql its hard for me to &amp;nbsp;get the output.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361924#M85437</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T11:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361925#M85438</link>
      <description>&lt;P&gt;Am grouping it by respndt.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361925#M85438</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T11:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361928#M85439</link>
      <description>&lt;P&gt;Sort by respndt.&lt;/P&gt;
&lt;P&gt;Use by respndt in the data step.&lt;/P&gt;
&lt;P&gt;Use first.respndt to reset the counters, and last.respndt to output.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361928#M85439</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-26T11:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361932#M85440</link>
      <description>&lt;P&gt;Ah, well that simplfies it then:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  RESPNDT,
          count(case when COMPLETED="Yes" then 1 else 0 end) as COMPLETED,
          count(*) as TOTAL_COUNT
  from    ABC
  group by RESPNDT;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 May 2017 12:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361932#M85440</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-26T12:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361942#M85444</link>
      <description>&lt;P&gt;but my result should be like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;respndt Completed total_cont&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;aa 1 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bb 2 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for respndt "aa" there is completed="yes"---1, and one "yes" and one "no" ---2, which is (respndt=aa&amp;nbsp;Completed=1&amp;nbsp;total_cont=2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for respndt "bb" there is&amp;nbsp;completed="yes"---2,and two "yes" and two "no" ---4, which is (respndt=bb Completed=2 total_cont=4)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 12:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361942#M85444</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T12:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361946#M85446</link>
      <description>&lt;P&gt;Sorry, should have used sum() rather than count():&lt;/P&gt;
&lt;PRE&gt;data abc;
input respndt$ name$ completed$;
datalines;
aa ksv yes
aa kbc no
bb xab no
bb gfg no
bb ghg yes
bb gkg yes
;
run;
proc sql;
  create table WANT as
  select  RESPNDT,
          sum(case when upcase(COMPLETED)="YES" then 1 else 0 end) as COMPLETED,
          count(*) as TOTAL_COUNT
  from    ABC
  group by RESPNDT;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 May 2017 13:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/361946#M85446</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-26T13:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/362025#M85478</link>
      <description>&lt;P&gt;Thank you RW9&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 15:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/362025#M85478</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T15:58:14Z</dc:date>
    </item>
  </channel>
</rss>

