<?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: Calculating percentage in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391911#M277679</link>
    <description>&lt;P&gt;More than $25 in total or had at least one purchase exceeding $25? 100 percent of those ID's spent more than $25 in total. 20 percent of those ID's had at least one expenditure exceeding $25 dollars.&lt;BR /&gt;&lt;BR /&gt;Which is the correct answer?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for amusement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expenditures;
   input spending 8.2 id;
datalines;
15.48	1
10.91	1
11.47	1
25.32	1
14.01	1
23.08	3
10.38	3
14.01	3
17.98	3
527.18	4
625.6	4
642.27	4
22.3	5
48.43	5
49.48	5
3.79	6
2.63	6
3.46	6
6.57	6
16.41	6
;
run;

data flagged_expenditures;
	set expenditures;
	big_spender = 0;
	if spending &amp;gt;= 25 then big_spender = 1;
run;

proc sort data = flagged_expenditures;
	by id descending big_spender;
run;

data big_spenders;
	set flagged_expenditures;
	by id;
	if first.id;
run;

PROC FORMAT; 
VALUE big_spender_fmt
	0 = "Did not spend more than $25 on one purchase"
	1 = "Spent more than $25 on one purchase";
RUN; 

proc freq;
	tables big_spender;
	format big_spender big_spender_fmt.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                                       The FREQ Procedure

                                                                        Cumulative    Cumulative
                                big_spender    Frequency     Percent     Frequency      Percent

Did not spend more than $25 on one purchase           2       40.00             2        40.00
Spent more than $25 on one purchase                   3       60.00             5       100.00

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd edit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just becasue we can and it amuses me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table big_spenders2 as
	select 'Big Spender' as status, count(a.id) as mycount
	from (
	select id, sum(case when spending &amp;gt; 25 then 1 else 0 end) as big_spender
	from expenditures
	group by id) as a
	where a.big_spender &amp;gt;0
	union
	select 'Little Spender' as status, count(a.id) as mycount
	from (
	select id, sum(case when spending &amp;gt; 25 then 1 else 0 end) as big_spender
	from expenditures
	group by id) as a
	where a.big_spender = 0;
quit;

proc sql;
	create table big_spender_percentage as 
	select status, mycount / (select sum(mycount) from big_spenders2) as mypercent
	from big_spenders2;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yeilds&lt;/P&gt;
&lt;PRE&gt;                               Obs        status        mypercent

                                1     Big Spender          0.6
                                2     Little Spender       0.4

&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Aug 2017 18:30:23 GMT</pubDate>
    <dc:creator>HB</dc:creator>
    <dc:date>2017-08-30T18:30:23Z</dc:date>
    <item>
      <title>Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391431#M277675</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some data from groups of people spending money at a number of stores in a mall. I'm trying to calculate the percentage of people who spent at least 25 or more and at least&amp;nbsp;30 or more using proc report. I've attached the sas file and some of my code so far, but it is pretty basic. I assume I need to use sum and pctsum, but I don't how to incorporate them into the code correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc report data=mydata.house;&lt;BR /&gt;column id spent;&lt;BR /&gt;define id / display;&lt;BR /&gt;define spent / display;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;title1 'Expenditure per group';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 11:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391431#M277675</guid>
      <dc:creator>Dont</dc:creator>
      <dc:date>2017-08-29T11:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391504#M277676</link>
      <description>&lt;P&gt;It is better to post data in the form of datastep code such as generated with this:&amp;nbsp; &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS data sets from different operating systems may not work, depending on the options in effect a 9.4 data set may not run with 9.2 or 9.3, 32-bit vs 64-bit, lanuage encoding may cause issues. With a data step everyone can run the code on their system to recreate a data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say:&lt;/P&gt;
&lt;P&gt;"&amp;nbsp;I'm trying to calculate the percentage of people who spent at least 25 or more and at least&amp;nbsp;30 or more using proc report."&lt;/P&gt;
&lt;P&gt;is the 25 and 30 you reference a number of purchases (n) a total currency amount or some percent used as a group? When you mention percent you should clearly indicate what a numerator and denominator may be.&lt;/P&gt;
&lt;P&gt;If you provide a small data set that you can calculate the result by hand then it is a very good idea to show what you want the output to look like. Otherwise we have to make assumptions and then you get to say "what I really wanted was xxxxx" so start with the XXXX spelled out.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 14:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391504#M277676</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-29T14:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391509#M277677</link>
      <description>&lt;P&gt;You'll need to provide more context and perhaps some data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"people who spent at least 25 or more"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what that means.&amp;nbsp; People who had spending at 25 stores?&amp;nbsp; People who spent $25? People who exhausted themselves (became spent) 25 times?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data spending;
   input spending;
datalines;
25
20
15
30
35
40
35
60
;
run;


PROC FORMAT; 
VALUE spending_fmt
	0-25  = "Spent $25 or less"
	26 - HIGH  = "Spent more than $25";
RUN; 

proc freq data=spending;
tables spending / missing;
FORMAT spending spending_fmt.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                       The FREQ Procedure

                                                            Cumulative    Cumulative
                       spending    Frequency     Percent     Frequency      Percent
            
            Spent $25 or less             3       37.50             3        37.50
            Spent more than $25           5       62.50             8       100.00

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391509#M277677</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-08-29T15:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391805#M277678</link>
      <description>&lt;P&gt;Thank you very much for your input so far. I'm still working through how to use Mark Jordan's program so I've just posted an example of my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To clarify re: percentage, each ID represents a person. The 5 1s represent&amp;nbsp;separate purchases that 1 person made.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e. person 1 bought 5 items of varying cost. Person 3 bought 4 items of varying cost.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to calculate the percentage of people who spent more than 25 and more than 30 &amp;nbsp;using proc report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;15.48&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10.91&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11.47&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13.32&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14.01&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&g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/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 12:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391805#M277678</guid>
      <dc:creator>Dont</dc:creator>
      <dc:date>2017-08-30T12:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391911#M277679</link>
      <description>&lt;P&gt;More than $25 in total or had at least one purchase exceeding $25? 100 percent of those ID's spent more than $25 in total. 20 percent of those ID's had at least one expenditure exceeding $25 dollars.&lt;BR /&gt;&lt;BR /&gt;Which is the correct answer?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for amusement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expenditures;
   input spending 8.2 id;
datalines;
15.48	1
10.91	1
11.47	1
25.32	1
14.01	1
23.08	3
10.38	3
14.01	3
17.98	3
527.18	4
625.6	4
642.27	4
22.3	5
48.43	5
49.48	5
3.79	6
2.63	6
3.46	6
6.57	6
16.41	6
;
run;

data flagged_expenditures;
	set expenditures;
	big_spender = 0;
	if spending &amp;gt;= 25 then big_spender = 1;
run;

proc sort data = flagged_expenditures;
	by id descending big_spender;
run;

data big_spenders;
	set flagged_expenditures;
	by id;
	if first.id;
run;

PROC FORMAT; 
VALUE big_spender_fmt
	0 = "Did not spend more than $25 on one purchase"
	1 = "Spent more than $25 on one purchase";
RUN; 

proc freq;
	tables big_spender;
	format big_spender big_spender_fmt.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                                       The FREQ Procedure

                                                                        Cumulative    Cumulative
                                big_spender    Frequency     Percent     Frequency      Percent

Did not spend more than $25 on one purchase           2       40.00             2        40.00
Spent more than $25 on one purchase                   3       60.00             5       100.00

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd edit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just becasue we can and it amuses me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table big_spenders2 as
	select 'Big Spender' as status, count(a.id) as mycount
	from (
	select id, sum(case when spending &amp;gt; 25 then 1 else 0 end) as big_spender
	from expenditures
	group by id) as a
	where a.big_spender &amp;gt;0
	union
	select 'Little Spender' as status, count(a.id) as mycount
	from (
	select id, sum(case when spending &amp;gt; 25 then 1 else 0 end) as big_spender
	from expenditures
	group by id) as a
	where a.big_spender = 0;
quit;

proc sql;
	create table big_spender_percentage as 
	select status, mycount / (select sum(mycount) from big_spenders2) as mypercent
	from big_spenders2;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yeilds&lt;/P&gt;
&lt;PRE&gt;                               Obs        status        mypercent

                                1     Big Spender          0.6
                                2     Little Spender       0.4

&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/391911#M277679</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-08-30T18:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/392401#M277680</link>
      <description>&lt;P&gt;I'm interested in at least one purchase &amp;gt;25, who made 2 purchases&amp;gt;25 and then who made 3 purchases &amp;gt;25. After that I was planning on calculating it for different amounts (i.e. 30, 50 etc), but I was hoping I'd be able to do that myself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 01:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-percentage-in-proc-report/m-p/392401#M277680</guid>
      <dc:creator>Dont</dc:creator>
      <dc:date>2017-09-01T01:48:02Z</dc:date>
    </item>
  </channel>
</rss>

