BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sayan7
Calcite | Level 5
Code:
proc report data=deposits nowd;
column cust_id
amount_deposited     amount_deposited=deposit_count
amount_withdrawn    amount_withdrawn=withdraw_count
avg_dep_amt    avg_tran_count     avg_wdraw_count;

define cust_id/ group;
define amount_deposited / analysis sum noprint;
define amount_withdrawn / analysis sum noprint;
define deposit_count/ analysis n noprint;
define withdraw_count/ analysis n noprint;
define avg_dep_amt / computed 'avg. deposit amount';
define avg_tran_count / computed 'avg. no. of transactions';
define avg_wdraw_count / computed 'avg. no. of withdrawals';

compute avg_dep_amt;
avg_dep_amt = amount_deposited/deposit_count;
endcomp;

compute avg_tran_count;
avg_tran_count = (deposit_count + withdraw_count)/3;  /* there is a reason to divide by 3 */
endcomp;

compute avg_wdraw_count;
avg_wdraw_count = withdraw_count/3;   /* there is a reason to divide by 3 */
endcomp;
run;
 
Log:
NOTE: Variable amount_deposited is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
5 at 1:32

I can compute count the number of non-missing values of variable amount_deposited using alias, but I cannot compute sum of those values, log shows me that the variable is not initialized. What is the problem in SAS?
1 ACCEPTED SOLUTION
3 REPLIES 3
Sayan7
Calcite | Level 5

In that case can I define like:

define amount_deposited / analysis sum n noprint;

in order to find:

avg_dep_amt = amount_deposited.sum / amount_deposited.n ;

instead making a new variable?

Kurt_Bremser
Super User

As always, Maxim 1: Read the Documentation.

It contains this example for having multiple statistics for one variable without the use of aliases.

But N is a special case, as it does not depend on a variable, but counts the observations instead.