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. Which is the correct answer?
Edit:
Just for amusement.
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 >= 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;
yields
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
2nd edit:
And just becasue we can and it amuses me:
proc sql;
create table big_spenders2 as
select 'Big Spender' as status, count(a.id) as mycount
from (
select id, sum(case when spending > 25 then 1 else 0 end) as big_spender
from expenditures
group by id) as a
where a.big_spender >0
union
select 'Little Spender' as status, count(a.id) as mycount
from (
select id, sum(case when spending > 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;
yeilds
Obs status mypercent
1 Big Spender 0.6
2 Little Spender 0.4
... View more