While PROC REPORT and PROC SQL offer great flexibility, the most efficient native SAS method for aggregating massive datasets remains PROC SUMMARY (or PROC MEANS). It is worth clarifying that the NWAY option actually belongs to these procedures—not SQL—and is a crucial best practice when using a CLASS statement to optimize processing by suppressing unnecessary global subtotals in your output table.
In daily data processing, it is very common to need to switch from a "transactional" level of detail (multiple rows per customer) to a "summary" level (one row per customer with a total).
1. The Problem: Summing balances by customer
The user has a dataset containing customer numbers, dates, and amounts (balances). The same customer (Cust_1) appears multiple times on different dates.
Customer
Amount
Date
Cust_1
100.00
01/01/2008
Cust_1
150.00
10/01/2008
Cust_1
125.00
11/01/2008
Objective:
Create a new table containing the sum of the amounts for each customer.
Expected result for Cust_1: 375.00
Note : In the original discussion, an effective solution using PROC REPORT was provided. Although often used for display (printing), this procedure is very powerful for generating output tables.
proc report data=cust nowd out=temp;
column cust_no bal;
define cust_no / group noprint;
define bal / analysis sum noprint;
run;
Los códigos y ejemplos proporcionados en WeAreCAS.eu son con fines educativos. Es imperativo no copiarlos y pegarlos ciegamente en sus entornos de producción. El mejor enfoque es comprender la lógica antes de aplicarla. Recomendamos encarecidamente probar estos scripts en un entorno de prueba (Sandbox/Dev). WeAreCAS no acepta ninguna responsabilidad por cualquier impacto o pérdida de datos en sus sistemas.
SAS y todos los demás nombres de productos o servicios de SAS Institute Inc. son marcas registradas o marcas comerciales de SAS Institute Inc. en los EE. UU. y otros países. ® indica registro en los EE. UU. WeAreCAS es un sitio comunitario independiente y no está afiliado a SAS Institute Inc.
Este sitio utiliza cookies técnicas y analíticas para mejorar su experiencia.
Saber más.