<?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: Can we use case when and group by together? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/383444#M65591</link>
    <description>&lt;P&gt;You can use MAX/MIN with SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *, max(payment_method) as payment_method_max
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Jul 2017 19:08:18 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-27T19:08:18Z</dc:date>
    <item>
      <title>Can we use case when and group by together?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/383409#M65589</link>
      <description>&lt;P&gt;&amp;nbsp; I had a database like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Account_Number&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Payment_Method&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;PI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;PI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some data record error reason, for example, as the account number = 1, when month =0, the payment method should be PI instead of missing. but the account number 2 is fine. Since all of its months should be missing. So the correct database would be :all of the months should be PI or all of the months should be missing for the same account.&lt;/P&gt;&lt;P&gt;So my question is: for the account like 1, is that possible to let payment method = PI when month = 0? The problem only occur when month = 0 in the problem account.&lt;/P&gt;&lt;P&gt;I try &amp;nbsp;CASE WHEN MONTH = 1 AND Payment_method= 'PI'&lt;BR /&gt;THEN (CASE WHEN MONTH =0 THEN PAYMENT_METHOD = 'P' END)&lt;BR /&gt;end&lt;/P&gt;&lt;P&gt;group by Account_number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't work at all...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 18:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/383409#M65589</guid>
      <dc:creator>Linmuxi</dc:creator>
      <dc:date>2017-07-27T18:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use case when and group by together?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/383444#M65591</link>
      <description>&lt;P&gt;You can use MAX/MIN with SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *, max(payment_method) as payment_method_max
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 19:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/383444#M65591</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-27T19:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use case when and group by together?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/384113#M65630</link>
      <description>&lt;P&gt;Thank you! I added a group by and it works out!!!&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 22:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Can-we-use-case-when-and-group-by-together/m-p/384113#M65630</guid>
      <dc:creator>Linmuxi</dc:creator>
      <dc:date>2017-07-30T22:26:46Z</dc:date>
    </item>
  </channel>
</rss>

