#set TITLE = "proc tabulate"
#include top
 

.SH DESCRIPTION
\fBproc tabulate\fR may be used to compute a one-way distribution on one 
data field, or a two-way distribution using two data fields.
The results are then considered the "current"
data set for plotting.  
.LP
\fBproc tabulate\fR has a capacity of 200 result rows and 
60 result columns.
Data does not have to be ordered in any particular way.
See also the \fBproc processdata\fR \fCcount\fR action, which requires
ordered data but has no upper limit on number of "bins".
.LP
The \fCsavetable\fR feature is recommended so that you can see
what the data set will look like when developing a plot.

.SH FEATURES
Can tabulate to produce one- or two-way distributions.  
Bins may be based on natural occurance or by preset lists or ranges.  
Percents may be calculated.  Ordering of results may be controlled.
Occurances may be counted, or accumulations may be done.
Resulting text table may be displayed on screen or saved for other uses.

.SH EXAMPLES
See the Gallery examples
.ig >>
<a href="../gallery/distrib.htm">
.>>
distrib
.ig >>
</a>
.>>
and 
.ig >>
<a href="../gallery/vermonth.htm">
.>>
vermonth
.ig >>
</a>
.>>

.SH PREREQUISITES
\fBproc getdata\fR must first be executed to define or access some data.

.SH VARIABLES SET
.LP
\fBNROWS\fR = Number of rows in the data result.
.LP
\fBNFIELDS\fR = Number of fields per row in the data result.
.LP
Thus, if a one-way distribution is being done and there are 7 varieties,
NRECORDS will hold 7, which may then be used (e.g. xrange: @NRECORDS+1) 
to automatically set scaling for a bargraph.


.SH MODES
Either one-dimensional or two-dimensional modes.
.LP
If \fCdatafield1\fR is specified but \fCdatafield2\fR is not,
a \fBone-dimensional\fR distribution will be computed.
The result will be two data fields\(em the first field
will be the value and the second field will be the number of
instances.  The number of records in the result will be
the number of bins.
.LP
If both \fCdatafield1\fR and \fCdatafield2\fR are specified
then a \fBtwo-dimensional\fR distribution will be computed.
Datafield1 will be distributed downward and datafield2
will be distributed across.  
The result's column headings will be usable as field names
(the first column is always named \fCrowname\fR).
.LP
Many of the attributes are named with either 1 or 2
to correspond with either the distribution on
datafield1, or datafield2.

.SH NOTE
After \fBproc tabulate\fR executes, all subsequent plotting
procedures in the script file will access its results 
for plotting.  However,
the original data is still in memory.  If later it is
necessary to plot the original data, \fBproc originaldata\fR
may be invoked.



.SH MANDATORY ATTRIBUTES
The \fCdatafield1\fR attribute must be specified.
.LP
If a \fCvaluelist\fR is not specified, all values encountered will
get their own bin in the distribution.


.SH ATTRIBUTES
.LP
\fBdatafield1\fR 
.ig >>
<a href="attributetypes.html#dfield">
.>>
\fI dfield \fR
.ig >>
</a>
.>>
.IP
Compute a distribution on this data field.
Value will be in result data field 1 and N will be
in result data field2.
Example: \fCdatafield1: 1\fR

.LP
\fBdatafield2\fR 
.ig >>
<a href="attributetypes.html#dfield">
.>>
\fI dfield \fR
.ig >>
</a>
.>>
.IP
Compute a two way distribution on datafield1 and this field.
Distribution on datafield2 will be horizontal.
See also MODES above.
Example: \fCdatafield2: 5\fR

.LP
\fBaxis1\fR \fCx | y\fR
.IP
Axis to equivicate with the distribution on datafield1.
This needs to be specified when working with 
data which is to be scaled using units such as date or time.
Otherwise it does not need to be specified.

.LP
\fBaxis2\fR \fCx\fR|\fCy\fR
.IP
Same as \fCaxis1\fR.

.LP
\fBvaluelist1\fR \fIstringlist\fR
.IP
Define a set of values that will be included in the distribution
of datafield1.
The ordering of this set determines the order that categories 
are presented in the result.  
This is a space- or comma-delimited list of values.  
.br
Example: \fCvaluelist: red green blue\fR
.IP
If ranges are being used (\fCdorange1: yes\fR), then this attribute
may be used to explicitly define the ranges.  See the following example for
the syntax; by default, dash (-) is used to separate the low and hi
values in a range, with no embedded spaces allowed.
.IP
As a convenience, the letter "C" may be used in 
place of a low value in a range to
indicate "continuous"; its effect if for the previous high value to
be copied and taken as the next low value.
This saves the tedium and error-prone-ness 
of having to enter values twice.
.br
Example: \fCvaluelist1: 0-2.5 C-5 C-7.5 C-10\fR
.br
This would be equivalent to \fCvaluelist1: 0-2.5 2.5-5 5-7.5 7.5-10\fR.
Either way, a value of 2.5 would end up in the 2nd bin.

.LP
\fBvaluelist2\fR
.IP
Value list for datafield2.  (see valuelist1)

.LP
\fBdoranges1\fR \fCyes | no\fR
.IP
If \fCyes\fR, distribution on datafield1 will use ranges rather
than values.  If defined ranges overlap the higher bin has presidence.
The ranges may be defined using either \fCvaluelist1\fR, or 
\fCrangespec1\fR.

.LP
\fBdoranges2\fR \fCyes | no\fR
.IP
If \fCyes\fR, distribution on datafield2 will use ranges rather
than values.  
The ranges may be defined using either \fCvaluelist2\fR, or 
\fCrangespec2\fR.

.LP
\fBrangespec1\fR  \fIlowval  binsize\fR  [\fIhival\fR]
.IP
If doing ranges, this attribute may be used instead of \fCvaluelist\fR
if ranges of uniform size are to be used when tabulating.
Ranges will begin at \fIlowval\fR and be of size \fIbinsize\fR.
Ranges will end when \fIhival\fR is passed, or when the high end
of the axis is passed (if an axis has been defined).
\fIlowval\fR and \fIhival\fR should be 
.ig >>
<a href="attributetypes.html#plotvalue">
.>>
plotvalues
.ig >>
</a>
.>>
 .  Implies \fCdoranges1: yes\fR.
.br
Example: \fCrangespec1: 0 5 39\fR
.br
This would set up ranges 0-5, 5-10, 10-15, and so on, up to
35-40 (remember that where ranges overlap, the higher bin has presidence).

.LP
\fBrangespec2\fR  \fIlowval  binsize\fR  [\fIhival\fR]
.IP
Same as \fCrangespec1\fR, but for datafield2.

.LP
\fBaccumfield\fR 
.ig >>
<a href="attributetypes.html#dfield">
.>>
\fI dfield \fR
.ig >>
</a>
.>>
.IP
Normally, proc tabulate works by counting occurances.  However,
If \fCaccumfield\fR is specified, instead of counting, an accumulation
will be done using the specified field.  (New in version 1.34)

.LP
\fBorder1\fR \fCnatural | magnitude | reversemagnitude\fR
.IP
Specify order that categories are presented in the result.

.LP
\fBorder2\fR \fCnatural | magnitude | reversemagnitude\fR
.IP
Same as above for datafield2.

.LP
\fBpercents\fR  \fCyes\fR | \fCno\fR
.IP
If yes, each tabulation column will be accompanied by a column of percents.

.LP
\fBsavetable\fR \fIfilename\fR | \fCstdout\fR | \fCstderr\fR
.IP
If specified, write tabulation results to the
given file, standard output or standard error.

.LP
\fBselect\fR 
.ig >>
<a href="condex.html">
.>>
\fI conditional-expression \fR
.ig >>
</a>
.>>
.IP
\fIconditional-expression\fR 
is applied to each data record (row).
If specified and if the expression evaluates to true, the
data is included; otherwise it is excluded.
Data fields are referenced by preceding them with
two at-signs (@@).
.br
Example: \fCselect: @@4 = G\fR

.LP
\fBrangesepchar\fR \fIchar\fR
.IP
Allows user specification of the range separator character 
(the character that should be used
to separate the low and high values of a range in the valuelists).
Default range separator charactor is dash (-).
Example: \fCrangesepchar: ,\fR

.LP
\fBshowrange\fR \fClow\fR  |  \fCavg\fR
.IP
If specified, controls the content of row or column labels 
when ranges are being used.  Normal behavior is for the
label to be formatted \fIlowend\fC - \fIhiend\fR.
If this attribute is \fClow\fR, only the low value will be given.
If this attribute is \fCavg\fR, an average of the low and high
will be given.
This attribute is useful when proc tabulate result range bins will 
be plotted by location, e.g. for a histogram (the 1st result data
field can be used as the bar location).
New in version 1.40.


.LP
\fBshowrangelowonly\fR \fCyes | no\fR
.IP
[Superceded by the \fCshowrange\fR attribute.]
If \fCyes\fR and if ranges are being used, show only the low 
part of the range in the results.  


#include bottom
