In an analysis of recent accounts, suppose
that you also want to determine some statistics by customer. In the
following example, PROC MEANS is used to generate the mean debit amount
for each customer (including the number of observations (N) and the
number of missing values (NMISS)):
proc sort data=vlib.trans out=mydata.trandata;
by soc_sec_number;
run;
options nodate linesize=80;
proc means data=mydata.trandata mean
sum n nmiss maxdec=0;
by soc_sec_number;
var check_debit_amount;
title2 'Mean Debit Amount Per Customer';
run;
In the example, the view descriptor Vlib.Trans selects CUSTOMER, CHCKACCT, and CHCKDEBT
segment data from the IMS database AcctDBD. Since the AcctDBD database is an HDAM and therefore
is not indexed, the
data that is described by the view descriptor must be sorted before using PROC MEANS.
The sorted data is stored in a
SAS data file called MyData.TranData, which is then used as input to PROC MEANS.
If your database is indexed, you can use a SAS BY statement for the indexed
field so that data is returned as if it is sorted. Database access methods HIDAM, HISAM,
and SHISAM are indexed. If your database is not indexed, you need to sort the IMS
data before using the MEANS procedure with a BY statement. Because you cannot sort
data in an IMS database, you must use the OUT= option to extract data from the database
so that you can pass it to the MEANS procedure.
Note: You can store the sorted
data in a temporary data set if space is a concern.
Note: If the view descriptor describes
a path of data that includes segments from multiple hierarchical levels,
the parent segment information is repeated for each SAS observation.
This can cause misleading statistical results. To avoid misleading
results, perform mathematical operations using only the data in the
segment at the lowest hierarchical level. You can also avoid misleading
results by creating a view descriptor that describes only the data
in the segment at the lowest hierarchical level.
The following output
shows the output for this example.
Results of Calculating Statistics Using the MEANS Procedure
The SAS System
Mean Debit Amount Per Customer
-------------------------- SOC_SEC_NUMBER=156-45-5672--------------------------
The MEANS Procedure
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
27 110 4 0
------------------------------------------
-------------------------- SOC_SEC_NUMBER=178-42-6534--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
26 26 1 0
------------------------------------------
-------------------------- SOC_SEC_NUMBER=234-74-4612--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
. . 0 1
------------------------------------------
-------------------------- SOC_SEC_NUMBER=434-62-1224--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
162 1620 10 0
------------------------------------------
The SAS System
Mean Debit Amount Per Customer
-------------------------- SOC_SEC_NUMBER=434-62-1234--------------------------
The MEANS Procedure
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
. . 0 1
------------------------------------------
-------------------------- SOC_SEC_NUMBER=436-42-6394--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
. . 0 1
------------------------------------------
-------------------------- SOC_SEC_NUMBER=456-45-3462--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
66 263 4 0
------------------------------------------
-------------------------- SOC_SEC_NUMBER=657-34-3245--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
. . 0 1
------------------------------------------
-------------------------- SOC_SEC_NUMBER=667-73-8275--------------------------
The MEANS Procedure
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
355 1065 3 2
------------------------------------------
-------------------------- SOC_SEC_NUMBER=667-82-8275--------------------------
Analysis Variable : CHECK_DEBIT_AMOUNT CHECK_DEBIT_AMOUNT
N
Mean Sum N Miss
------------------------------------------
. . 0 1
------------------------------------------
For more information
about PROC MEANS, see SAS Language Reference: Concepts and the Base SAS Procedures Guide.