As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


ChekOut.sas

From sasCommunity
Jump to: navigation, search

This program is from this paper:

sugi23.197

SUGI23.197.1998, Poster, 3 pages, Best Contributed Paper (2nd Place)

CHEKOUT: A SAS(R) Program to Screen for Outliers

Author: James Handsfield,

Centers for Disease Control and Prevention, Atlanta, GA.

posted and polished by --macro maven == the radical programmer 10:44, 18 May 2007 (EDT)

Program

 /*  TLI OUTLIERS REPORT
2007-May-17 RJF2 polishing of original program
                 provided by J. Handsfield
            NOTE: This version is Not -exactly- what is in the paper!
 ***/
%Let PGMPATH  = .;%*here;
%Let InLibref = Library;
%Let InData   = Samples;
%Let PRNTFILE = zChekOut.txt;
 
%LET MODVARS = CD45POS CD14POS CD4COMB CD8COMB CD19COMB CD51COMB
               CD3COMB CD4CTCMB CD8CTCMB
               CD16COMB CD56COMB LYMPCT LYMCNT WBC;
%LET GLMVARS = R45 R14 R4 R8 R19 R51 R3 R4CT R8CT R16 R56 RLP RLC RWB;
 
%LET PRNTFILE = "&PGMPATH.\TLIOUT.SAS";
 
OPTIONS PAGENO=1 NOCENTER NOFMTERR MPRINT NODATE PS=57 LS=99;
*missing _;
 
;/*--------------------------------------------------------------------*
When printing, select PRINT SETUP and select PORTRAIT,
and a left margin of 0.6.
Use SAS MonoSpace 9 font for best presentation (PS=58 LS=96).
;/*-------------------------------------------------------------------*/
 
%*INCLUDE SASAUTOS(IDATE);
%let typeREPT = Outlier;
 
%*INCLUDE SASAUTOS(TLUTITLE);
 
 /*. Begin Macro Code ................................................*/
%MACRO ID(msg);
   if NOT ID then do;
      put   "IF MPEPNum = '" MPEPNum
        +B1 "' and FormNmbr = '" FormNmbr
        +B1 "' and DONOR = " DONOR
        +B1 "  and SAMPID = '" SAMPID
        +B1 "' "/" and OBSNUM = " OBSNUM
        +B1 "  then do;";
      ID = 1; *********************************************************;
      end;
   put "  *&msg.;"; *****************************************; 
%mend ID;
 
%MACRO SHOW(field);
   CALL VNAME(&FIELD,NAME);
   OUTL+1;
   put @1 "  *" @4 NAME @13 " = " &FIELD.  +B1";"; ********; 
%mend show;
 
%MACRO SHOW2(field);
   CALL VNAME(&FIELD,NAME);
   put @1 "  *" @4 NAME @13 " = " &FIELD.  +B1";"; *******; 
%mend show2;
 
%MACRO SHOW3(field);
   CALL VNAME(&FIELD,NAME);
   put @1 "   " @4 NAME @13 " = . "  +B1";";       *******; 
%mend show3;
 
 /*..... End Macro Code ..............................................*/
 
%*PROC SORT DATA = LIBRARY.SAMPLES;
PROC SORT DATA = &InLibref..&InData.
          OUT  = SAMPLES;
          BY     DONOR;
 
PROC GLM DATA     = SAMPLES NOPRINT;
        *CLASS      DONOR;
         BY         DONOR;
         MODEL      &MODVARS. = DONOR;
         OUTPUT
         OUT      = UPP
         RSTUDENT = &GLMVARS.;
 
PROC SORT DATA = UPP
          OUT  = RANGE;
          BY     MPEPNUM FORMNMBR DONOR;
 
DATA   _NULL_;
retain B1    -1;  /* Pointer Control */
retain total  0;
retain outl   0;
 
file &PRNTFILE;
 
set RANGE end = EndoFile;
 
LENGTH ID 3;  ID = 0;
LENGTH NAME $8; /* Used in MACRO SHOW */
 
/*  Array Processing for output variables  */
 
array OUTLIER{*} 3  &GLMVARS.;
 
array SCORE{*} 3    &MODVARS.;
 
DO I = 1 TO DIM(SCORE);
   IF SCORE{i} NE . THEN TOTAL+1;
   end;
 
DO I = 1 TO DIM(OUTLIER);
   IF (   ABS(OUTLIER{i}) GE 3   ) THEN DO;
      %ID(REVIEW:  OUTLIER)
      %SHOW(OUTLIER{i})
      %SHOW2(SCORE{i})
      %SHOW3(SCORE{i})
      end;**** ABS GE &STATVAL ***********;
   end;*** Array Processing****;
 
IF ENDOFILE THEN DO;
   PCTOUT = (OUTL/TOTAL);
   FORMAT PCTOUT PERCENT8.2;
   END;
 
/*  End of Record -- NO EDITS BELOW THIS LINE *************************/
 
if ID  then put "END; *MPEPNum PROCESSING;";
 
if EndoFile then
   put "*Number of OUTLIERS = " OUTL ";"
     / "*Number of RESULTS  = " TOTAL ";"/
       "*Percent OUTLIERS   = " PCTOUT ";"/
       "****END OF JOB;";
 
data _NULL_;
file PRINT;
do until(EndoFile);
   infile &PRNTFILE end = EndoFile pad lrecl = 88;
   input @1 Line $char88.;
   put   @1 Line $char88.;
   end;
stop;
 
RUN;

References