# Return to Minitab macro index

# How to save this page as a macro

# FNS.MAC
#
# Finds the five-number summary for a set of data.
# Computes Q1 and Q3 differently than Minitab's usual practice.
# 03/10/98
# DKN
#

macro
fns x.1-x.n;
  counts c;
  by Grp.

#################################
###       declarations        ###
#################################
mcolumn x.1-x.n c tmp Grp
mcolumn ColNum Categ Freq Min Q1 Med Q3 Max IQR
mcolumn tColNum tCateg tFreq tMin tQ1 tMed tQ3 tMax
mconstant a n

#################################
###          main body        ###
#################################

brief 0

if counts=1
 # Can't handle freqs right now.
else
 DO a = 1:n
  LET tColNum = a
  IF BY = 1
   STATS x.a;
     BY Grp;
     GVALUES tCateg;
     N      tFreq;
     MINIM  tMin;
     QONE   tQ1;
     MEDIAN tMed;
     QTHREE tQ3;
     MAXIM  tMax.
   LET tColNum(N(tFreq)) = '*'
  ELSE
   LET TCateg = 0
   STATS x.a;
     N      tFreq;
     MINIM  tMin;
     QONE   tQ1;
     MEDIAN tMed;
     QTHREE tQ3;
     MAXIM  tMax.
   IF tFreq/2 = ROUND(tFreq/2)
     LET tmp = x.a
     LET tmp(tFreq+1) = tMed
     STATS tmp;
       QONE   tQ1;
       QTHREE tQ3.
   ENDIF
  ENDIF
  STACK ColNum tColNum ColNum
  STACK Categ tCateg Categ
  STACK Freq tFreq Freq
  STACK Min tMin Min
  STACK Q1 tQ1 Q1
  STACK Med tMed Med
  STACK Q3 tQ3 Q3
  STACK Max tMax Max
 ENDDO
endif

LET IQR = Q3-Q1
BRIEF 2
IF BY = 1
  IF n>1
    PRINT ColNum Categ Freq Min Q1 Med Q3 Max IQR
  ELSE
    PRINT Categ Freq Min Q1 Med Q3 Max IQR
  ENDIF
ELSE
#  IF n>1
#    PRINT ColNum Freq Min Q1 Med Q3 Max IQR
#  ELSE
    PRINT Freq Min Q1 Med Q3 Max IQR
#  ENDIF
ENDIF

ENDMACRO