aggregation aggregate

Monthly Customer Transaction Analysis

Scénario de test & Cas d'usage

Business Context

A retail bank needs to generate a monthly summary of customer transactions. The goal is to calculate the total transaction amount, the average transaction value, and the number of transactions for each customer and account type. This summary will be used by financial advisors to review customer activity.
About the Set : aggregation

Data aggregation and summary statistical calculations.

Discover all actions of aggregation
Data Preparation

Creation of a sample customer transaction table. It includes customer IDs, account types, transaction dates, and amounts over several months.

Copied!
1DATA casuser.customer_transactions;
2LENGTH CustomerID $10 AccountType $15;
3FORMAT TransactionDate yymmdd10.;
4INFILE DATALINES delimiter=',';
5INPUT CustomerID $ AccountType $ TransactionDate :date9. Amount;
6DATALINES;
7CUST001,SAVINGS,01JAN2023,150.00
8CUST001,SAVINGS,15JAN2023,200.50
9CUST002,CHECKING,05JAN2023,1200.00
10CUST001,CHECKING,20JAN2023,350.75
11CUST002,CHECKING,28JAN2023,85.00
12CUST001,SAVINGS,10FEB2023,55.00
13CUST001,CHECKING,12FEB2023,1300.00
14CUST002,SAVINGS,15FEB2023,500.00
15CUST002,CHECKING,25FEB2023,250.25
16CUST001,SAVINGS,05MAR2023,95.20
17;
18RUN;

Étapes de réalisation

1
Load the source table into CAS memory.
Copied!
1 
2PROC CASUTIL;
3load
4DATA=casuser.customer_transactions outcaslib='casuser' casout='customer_transactions' replace;
5QUIT;
6 
2
Execute the aggregate action to summarize transactions by CustomerID, AccountType, and Month.
Copied!
1PROC CAS;
2 aggregation.aggregate /
3 TABLE={name='customer_transactions', groupBy={'CustomerID', 'AccountType'}},
4 id='TransactionDate',
5 interval='MONTH',
6 align='BEGINNING',
7 varSpecs={{name='Amount', agg='sum mean n'}},
8 casOut={name='monthly_summary', caslib='casuser', replace=true};
9RUN;
10QUIT;
3
Verify the aggregated output.
Copied!
1 
2PROC PRINT
3DATA=casuser.monthly_summary;
4title 'Monthly Transaction Summary by Customer and Account Type';
5RUN;
6 

Expected Result


The output table 'monthly_summary' should contain one row for each unique combination of CustomerID, AccountType, and month. Each row will display the total sum, mean, and count of transaction amounts for that group, with the timestamp aligned to the beginning of each month.