I have a dataset that includes product, hh_count and balances. I am trying to use hh_count and balances to get an average balance and then a total at the bottom.
Here is my code:
proc report data=bal_change2
style(report)={BORDERCOLOR=black BORDERWIDTH=1}
style(column)={BORDERCOLOR=black}
style(header)={BORDERCOLOR=black background = #DBE5F1 foreground=black}
style(summary)={font_weight=bold font_style=Roman};
options missing = ' ';
columns ('Deposit Balance Stratification 2020' (prod_group hh_cnt) strat_bl, (hh_cnt=hh_cnt2 balance_incr avg_bal_incr2));
define prod_group / Group left 'Product';
define hh_cnt / analysis 'HH Count' format=comma12.0;
define strat_bl / across 'Tier';
define hh_cnt2 / analysis 'HHs' format=comma12.0;
define balance_incr / analysis 'Balance Incr' format=dollar12.0;
define avg_bal_incr2 / computed 'Avg Balance Increase' format=dollar12.0;
compute avg_bal_incr2;
avg_bal_incr2=balance_incr/hh_cnt2;
endcomp;
rbreak after / summarize;
run;
The result I am getting for average balance is blank, but I can't figure out what I'm doing wrong.
Deposit Balance Stratification 2020 | ||||||
Tier | ||||||
$0 - $1,000 | $1,000 - $2,500 | |||||
Product | HH Count | HHs | Balance Incr | Avg Balance Increase | HHs | Balance Incr |
Enhanced | 228,008 | 21,936 | $40,775,269 | 30,539 | $70,894,035 | |
Essential | 1,401,419 | 569,177 | $538,610,905 | 315,773 | $558,937,924 | |
Express | 101,736 | 96,943 | $49,936,179 | 3,109 | $4,390,152 | |
Free | 234,756 | 174,102 | $134,095,346 | 31,062 | $52,489,296 | |
Other | 40,763 | 27,332 | $19,941,200 | 5,502 | $10,131,858 | |
Preferred | 153,572 | 14,036 | $43,309,240 | 14,252 | $43,641,635 | |
2,160,254 | 903,526 | $826,668,139 | 400,237 | $740,484,900 |
Your variable is summed, so the syntax is:
proc report data=SASHELP.CLASS;
columns AGE WEIGHT AVG;
define AGE / group;
define WEIGHT/ analysis sum;
define AVG / computed;
compute AVG;
AVG=WEIGHT.sum/2;
endcomp;
run;
When you get an error please copy the entire procedure and all notes, warning or errors from the LOG and paste into a code box opened on the forum with the </> icon. The code box is important because the log often contains diagnostic characters and the positions are important but the main message windows will reformat text.
And why are you using 'BALANCE_INCR.SUM'n? That would indicate that you already have a variable in your data set, or are creating one with that name. I would expect BALANCE_INCR.SUM to work just fine since Balance_incr is a standard SAS variable name. The statistic references in proc report using the .<statistic> do not have the statistic as part of the variable name.
Cant test as I don't have your data, but either syntax works for me:
proc report data=SASHELP.CLASS;
columns AGE WEIGHT HEIGHT AVG AVG1;
define AGE / group;
define WEIGHT/ analysis sum;
define AVG / computed;
compute AVG1;
AVG=WEIGHT.sum/_C3_;
AVG1=WEIGHT.sum/HEIGHT.sum;
endcomp;
run;
Age | Weight | Height | AVG | AVG1 |
---|---|---|---|---|
11 | 135.5 | 108.8 | 1.2454044 | 1.2454044 |
12 | 472 | 297.2 | 1.5881561 | 1.5881561 |
13 | 266 | 184.3 | 1.443299 | 1.443299 |
14 | 407.5 | 259.6 | 1.5697227 | 1.5697227 |
15 | 469.5 | 262.5 | 1.7885714 | 1.7885714 |
16 | 150 | 72 | 2.0833333 | 2.0833333 |
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.