<?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: Using count function with CASE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767862#M243487</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain total_saved total_policies sv;
set have;
by user notsorted policy_no;
if first.user
then do;
  total_saved = 0;
  total_policies = 0;
end;
if first.policy_no
then do;
  total_policies + 1;
  sv = 0;
end;
sv = max(sv,saved);
if last.policy_no then total_saved + sv;
if last.user;
drop sv saved policy_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Sep 2021 10:49:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-09-15T10:49:48Z</dc:date>
    <item>
      <title>Using count function with CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767861#M243486</link>
      <description>&lt;P&gt;Hi I need help in counting the distinct policy_no, where saved=1 as well as counting number of all distinct policies..see below data HAVE and WANT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data HAVE;
input Saved policy_no user : $20.;
datalines;
1 1 ALUPIYA
1 1 ALUPIYA
0 2 ALUPIYA
1 3 ALUPIYA
0 5 DLOUIS
1 4 DLOUIS
1 4 DLOUIS
1 6 DMORAKE
1 7 DMORAKE
1 8 DMORAKE
0 9 DMORAKE

;

data WANT;
input Total_Saved Total_policies user : $20.;
datalines;
2 3 ALUPIYA
1 2 DLOUIS
3 4 DMORAKE
;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 10:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767861#M243486</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-09-15T10:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using count function with CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767862#M243487</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain total_saved total_policies sv;
set have;
by user notsorted policy_no;
if first.user
then do;
  total_saved = 0;
  total_policies = 0;
end;
if first.policy_no
then do;
  total_policies + 1;
  sv = 0;
end;
sv = max(sv,saved);
if last.policy_no then total_saved + sv;
if last.user;
drop sv saved policy_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Sep 2021 10:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767862#M243487</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-15T10:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using count function with CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767867#M243492</link>
      <description>Thanks a lot Kurt, it works perfectly fine!</description>
      <pubDate>Wed, 15 Sep 2021 10:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767867#M243492</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-09-15T10:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using count function with CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767873#M243497</link>
      <description>Hi Kurt, i have other variables other than those ones i have mentioned above that i need to include , for example I have Variable user_type(I ,O R)..how do I include it within the final dataset WANT?</description>
      <pubDate>Wed, 15 Sep 2021 12:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767873#M243497</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2021-09-15T12:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using count function with CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767879#M243503</link>
      <description>&lt;P&gt;Since you do have some kind of summary in this, you need to decide how you do that for additional variables. You will need more retained variables to keep the state you want.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 12:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-count-function-with-CASE/m-p/767879#M243503</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-15T12:12:42Z</dc:date>
    </item>
  </channel>
</rss>

