<?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: How to - Get Count of More than One Condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305120#M65053</link>
    <description>Use PROC FREQ instead, it's part of the default output. Doing running totals is possible but a pain in SQL.</description>
    <pubDate>Mon, 17 Oct 2016 15:25:50 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-17T15:25:50Z</dc:date>
    <item>
      <title>How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305078#M65037</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample data set as below. I want to perform more than one condition in one column. I think I need to use PROC SQL but I just can't handle&amp;nbsp;it. My desired output is at the end of this message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Date 8 Turnover 8 Customer_ID 8;
Infile Datalines Missover;
Input Date Turnover Customer_ID;
Format Date Date9.;
Datalines;
20393 0 001
20423 100 002
20454 1000 003
20485 100 004
20514 100 005
20545 10 006
20575 0 007
20636 1000 008
20667 100 009
20698 100 010
20728 10 011
20759 100 012
20789 1000 013
20820 1000 014
20851 0 015
20879 10 016
20910 100 017
20940 1000 018
20971 100 019
21001 10 020
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5314i41E287690B458467/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Out.png" title="Out.png" /&gt;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305078#M65037</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-10-17T13:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305086#M65042</link>
      <description>&lt;P&gt;Use a PROC FORMAT + FREQ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first example in this paper is similar to your example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305086#M65042</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-17T13:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305090#M65043</link>
      <description>&lt;P&gt;Well, this works. &amp;nbsp;Basically createa category, then count by that:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as 
  select  CAT,
          count(distinct CUSTOMER_ID) as RESULT
  from    (select case  when TURNOVER = 0 then "Equal 0 -&amp;gt;"
                        when 0 &amp;lt; TURNOVER &amp;lt;=10 then "0&amp;gt; And &amp;lt;=10"
                        when 10 &amp;lt; TURNOVER &amp;lt;=100 then "10&amp;gt; And &amp;lt;=100"
                        when 100 &amp;lt; TURNOVER &amp;lt;=1000 then "100&amp;gt; And &amp;lt;=1000"
                        else "" end as CAT,
                   CUSTOMER_ID
           from    HAVE)
  group by CAT;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305090#M65043</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-17T13:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305096#M65046</link>
      <description>&lt;P&gt;Format and proc freq. You only need to dapt the proc format to make changes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value turnover
  0 = 'Equal 0'
  0 &amp;lt;- 10 = '0&amp;gt; and &amp;lt;=10'
  10 &amp;lt;- 100 = '10&amp;gt; and &amp;lt;=100'
  100 &amp;lt;- 1000 = '100&amp;gt; and &amp;lt;=1000'
;
run;

data have;
length date 8 turnover 8 customer_ID 8;
infile datalines missover;
input date turnover customer_ID;
format
  date date9.
  turnover turnover.
;
datalines;
;
run;

proc freq data=have;
tables turnover /out=want (drop=percent) nopercent nocum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2016 14:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305096#M65046</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-17T14:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305118#M65052</link>
      <description>&lt;P&gt;Thank you all of them,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I got my response but what if I want to add cumulative and percentage columns by using PROC SQL, how can I do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my desired output,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5323iB88A9B34F0474898/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Out2.png" title="Out2.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 15:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305118#M65052</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-10-17T15:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305120#M65053</link>
      <description>Use PROC FREQ instead, it's part of the default output. Doing running totals is possible but a pain in SQL.</description>
      <pubDate>Mon, 17 Oct 2016 15:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305120#M65053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-17T15:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305128#M65055</link>
      <description>&lt;P&gt;Yes, thank you very much but I just wonder how can I do it by using PROC SQL &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 15:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305128#M65055</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-10-17T15:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305139#M65059</link>
      <description>&lt;P&gt;Well, percentage is pretty easy as that is a calculation. &amp;nbsp;Cumulative however is not easy, in fact it is very difficult. &amp;nbsp;The reason is that SQL does not relate code to observations in a particular order. &amp;nbsp;So for percentage:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as 
  select  CAT,
          count(distinct CUSTOMER_ID) as RESULT,&lt;BR /&gt;          (CALCULATED RESULT / (select count(disinct CUSTOMER_ID from HAVE)) * 100 as PCENT
  from    (select case  when TURNOVER = 0 then "Equal 0 -&amp;gt;"
                        when 0 &amp;lt; TURNOVER &amp;lt;=10 then "0&amp;gt; And &amp;lt;=10"
                        when 10 &amp;lt; TURNOVER &amp;lt;=100 then "10&amp;gt; And &amp;lt;=100"
                        when 100 &amp;lt; TURNOVER &amp;lt;=1000 then "100&amp;gt; And &amp;lt;=1000"
                        else "" end as CAT,
                   CUSTOMER_ID
           from    HAVE)
  group by CAT;
quit;&lt;/PRE&gt;
&lt;P&gt;And then for cumulative, I would just add a datastep after that, sorted the way you want, and retain the cumulative as you go. &amp;nbsp;Doing it in teh SQL, the simplest way would just be to select each of the four categories, then union all together - i.e. the above code would be multipled by four rather than having the cat and grouping by that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 16:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305139#M65059</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-17T16:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305149#M65060</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the other hand, for Proc tabulate&amp;nbsp;procedure which statement should I add for cumulative calculation column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, following procedure-&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC TABULATE DATA=HAVE;	
CLASS Turnover /ORDER=UNFORMATTED MISSING;
TABLE /* Row Dimension */Turnover,
/* Column Dimension */N ColPctN ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 17:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305149#M65060</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-10-17T17:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305153#M65061</link>
      <description>&lt;P&gt;Proc tabulate does not do a running cumulative. It will do a TOTAL.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 17:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305153#M65061</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-17T17:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305157#M65062</link>
      <description>&lt;P&gt;Okay, so here is my final question, what if I want to create following table which procedure should I use it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5324iB418DC60C1092FD6/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Des.png" title="Des.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 17:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305157#M65062</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-10-17T17:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305162#M65063</link>
      <description>&lt;P&gt;PROC FREQ is 3 lines of code...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your table is the definition of the output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint;
tables turnover /out=want outpct outcum ;
run;

proc print data=want label noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 17:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305162#M65063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-17T17:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Count of More than One Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305291#M65104</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/48505"&gt;@turcay&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Okay, so here is my final question, what if I want to create following table which procedure should I use it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5324iB418DC60C1092FD6/image-size/original?v=v2&amp;amp;px=-1" alt="Des.png" title="Des.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just omit the &lt;FONT face="courier new,courier"&gt;nopercent&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;nocum&lt;/FONT&gt; option in the &lt;FONT face="courier new,courier"&gt;tables&lt;/FONT&gt; statement, and remove the &lt;FONT face="courier new,courier"&gt;drop=percent&lt;/FONT&gt; dataset option. You then get the default output of proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS you really need to develop a knack for reading the SAS documentation. Google "sas proc freq tables", and you get the correct page; all the options are thoroughly described there.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 06:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Count-of-More-than-One-Condition/m-p/305291#M65104</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-18T06:12:14Z</dc:date>
    </item>
  </channel>
</rss>

