Online File

How to use this page


Rick Aster: Professional SAS Programming Secrets: Contents

Chapter 10
Program 10q
Summary statistics in data step


*
  Professional SAS Programming Secrets
  Program 10q
  Summary statistics in data step
*;

data work.group (keep=group count x1sum x1n x1min x1max
    x2sum x2n x2min x2max);
   retain count x1sum x1n x1min x1max x2sum x2n x2min x2max;
   set work.detail;
   by group;

   if first.group then do;
      call missing(x1sum, x1min, x1max, x2sum, x2min, x2max);
      x1n = 0;
      x2n = 0;
      count = 0;
      end;

   count + 1;
   if not missing(x1) then x1n + 1;
   x1sum + x1;
   if not missing(x1) and (missing(x1min) or x1 < x1min)
       then x1min = x1;
   if x1 > x1max then x1max = x1;
   if not missing(x2) then x2n + 1;
   x2sum + x2;
   if not missing(x2) and (missing(x2min) or x2 < x2min)
       then x2min = x2;
   if x2 > x2max then x2max = x2;

   if last.group then do;
      if x1n then x1mean = x1sum/x1n;
      if x2n then x2mean = x2sum/x2n;
      output;
      end;
run;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Secrets

Contents/Online Files

Corrections