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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 867 views
  • 2 likes
  • 2 in conversation