Previous Topic: 5.5.2 Defining a File Summarization ProcessNext Topic: 5.5.4 Augmenting the Summarization with %NEGATE


5.5.3 Structure and Operation of the Summary Macro


The summary macros (%fffSUM) operate on a simple set of
rules.  Based on what was defined through the &BY and &BREAK
macro variables, the macro summarizes the data on the
following basis:

o The parameter list defined with the &BY variable should
  have been used for the SORT BY option, if a SORT was
  required. Regardless of the SORT use, the parameter list of
  the &BY variable is used to establish the BY option for the
  SET statement defined prior to the macro's invocation. It
  is the presence of this SET BY definition that enables the
  summary macro to use the SAS FIRST and LAST facilities.

o Using the variable name defined in the &BREAK variable, IF
  FIRST.&BREAK and IF LAST.&BREAK are used to determine
  control points in the summarization processing.

  Using the IF FIRST.&BREAK (where &BREAK is the most minor
  variable in the summary sequence), the routine executes the
  summarization initialization DO GROUP, where counters for
  all accumulated variables and storage variables for MIN/MAX
  derivation are set equal to their corresponding variables
  in the first observation for the summary group.

  On all observations but the first within the ones to be
  summarized, the routine executes the standard accumulation
  DO GROUP, where all variables to be accumulated are summed
  and MIN/MAX variables are tested to see if new MIN/MAX
  values should be set.

  Using the IF LAST.&BREAK, the routine executes the
  summarization termination DO GROUP where all computed
  variables are recomputed, including averages, per second
  rates, percentages, and uniquely computed variables (for
  example, working set size).
The following code shows the basic SAS statement structure
and how the statements expand after macro substitution:

Original SAS Statements
-----------------------

%LET BY = SYSID YEAR MONTH DAY ;
%LET BREAK = DAY ;
PROC SORT DATA=&PCPUD..HARCPU01 OUT=CPUSORT; BY &BY;
DATA CPUBYDA;
SET CPUSORT;
%CPUSUM;

Expanded SAS Statements Following Macro Substitution
----------------------------------------------------

   BY SYSID YEAR MONTH DAY;  * BY option for SET;
IF FIRST.DAY THEN DO;
  Initialize all accumulated variables (T_01039=CPUTODTM).
END;
ELSE DO;
  Sum all variables (T_01039+CPUTODTM).
  Derive minimums (T_00741=MIN(T_00741,CPUMNONL)).
  Derive maximums (T_00755=MAX(T_00755,CPUMXCPU)).
END;
IF LAST.DAY THEN DO;
  Compute averages, percentags, per second rates, and
     uniquely computed variables, such as total commands:
     CPUDD=CPUAA+CPUBB+CPUCC;
  OUTPUT;  * the new observation;
END;

Note: For more information, see the macro code that is stored
in sharedprefix.MICS.MACAUTOS members fffSUM.  Note that
parallel files, such as BAT_TS, have summary macros names
_ffSUM, but reside in the MACAUTOS library as #ffSUM members.
SAS tranlates the request for _TSSUM into the member name
#TSSUM when the macro is loaded.