Hello all,
I am new to SAS, and I would like help creating code for percent change bins, and it also counts the number of bills within each bin and the average of the old and new bills. The bins range from < -0.2 to >= 0.2 increasing by 0.05. Any help would be greatly appreciated.
< -0.2
-0.2 to -0.15
-0.15 to -0.1
So on.
Input
OldBill |
NewBill |
PercentChange |
$124.10 |
$149.13 |
20% |
$107.63 |
$132.29 |
23% |
$97.68 |
$130.62 |
34% |
$147.68 |
$161.38 |
9% |
$212.68 |
$190.74 |
(10%) |
$376.64 |
$266.43 |
(29%) |
$425.59 |
$292.86 |
(31%) |
$383.71 |
$271.55 |
(29%) |
$378.74 |
$269.02 |
(29%) |
$223.95 |
$190.27 |
(15%) |
$119.50 |
$139.74 |
17% |
$121.51 |
$143.21 |
18% |
$21.58 |
$23.89 |
11% |
$27.91 |
$22.82 |
(18%) |
$26.23 |
$22.03 |
(16%) |
Output
Percent Change |
NumberBills |
AvgOldBill |
AvgNewBill |
<-0.2 |
4 |
$391.17 |
$274.96 |
-0.2--0.15 |
3 |
$92.70 |
$78.37 |
-0.15--0.1 |
1 |
$212.68 |
$190.74 |
0.05-0.1 |
1 |
$147.68 |
$161.38 |
0.1-0.15 |
1 |
$21.58 |
$23.89 |
0.15-0.2 |
2 |
$120.51 |
$141.47 |
>0.2 |
3 |
$109.80 |
$137.35 |
A custom format for the percent of change will help do the grouping BUT first you need to indicate which end of the ranges the exact values belong in.
For example you show a value of 20%, which would be .2. With displayed bound of 0.15 - 0.2 and >0.2 which one does it display?
so is the range actually:
0.15 (inclusive) up to but not including 0.2
not including 0.15 up to and including 0.2
And is the pattern consisitent as is is the lower bound or upper bound inclusive for each value?
I am guessing that you could want something like
proc format;
value myperc
low -< -0.2 = '<-0.2'
-0.2 -< -0.15 = '-0.2 < -0.15'
-0.15 -< -0.1 = '-0.15 < -0.1'
-0.1 -< -0.05 = '-0.1 < -0.05'
-0.05 -< 0 = '-0.05 < 0'
0 -< 0.05 = ' 0 < 0.05'
0.05 -< 0.1 = '0.05 < 0.1'
0.1 -< 0.15 = '0.1 < 0.15'
0.15 -< 0.2 = '0.15 < 0.2'
0.2 - high = '>0.2'
run;
proc tabulate data= have;
class percentchange /order=internal;
format percentchange myperc.;
var OldBill NewBill;
table percentchange, n='NumberBills' (OldBill='AvgOldBill' NewBill='AvgNewBill')*mean=''*f=Dollar9.2;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.