1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
|
.ig >>
<STYLE TYPE="text/css">
<!--
A:link{text-decoration:none}
A:visited{text-decoration:none}
A:active{text-decoration:none}
OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }
H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>ploticus: proc processdata</title>
<body bgcolor=D0D0EE vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550><tr>
<td>
<table cellpadding=2 width=550><tr>
<td><br><h2>proc processdata</h2></td>
<td align=right>
<small>
<a href="../doc/welcome.html"><img src="../doc/ploticus.gif" border=0></a><br>
Version 2.33 Jun'06
</small><br><a href="../doc/scripthome.html">Scripts</a>
<td></tr></table>
</td></tr>
<td>
<br>
<br>
.>>
.TH proc_processdata PL "02-JUN-2006 PL ploticus.sourceforge.net"
.LP
\fBproc processdata\fR performs various types of manipulations on the
.ig >>
<a href="dataformat.html#currentds">
.>>
\0current data set.
.ig >>
</a>
.>>
Here are some of the things this proc can do:
.IP \0
- accumulate
.IP \0
- break processing
.IP \0
- count/summate on instances
.IP \0
- joins
.IP \0
- row numbering
.IP \0
- compute percents
.IP \0
- reverse row order
.IP \0
- rotation of row/column matrix
.IP \0
- find mean, sd, min, max
.IP \0
- compute totals
.LP
The \fCaction\fR attribute controls the type of processing to be done.
The result is usually a new data set (but sometimes the result is simply
the setting of some variables, as with \fCaction: totals\fR).
.LP
When a new data set is created, it will be kept in memory along with the original data by default.
To discard the new data set and return to the original one, use
.ig >>
<a href="usedata.html">
.>>
\0proc usedata.
.ig >>
</a>
.>>
For large data sets you can cause the result to overwrite the
original data set in memory by setting (\fCstack: no\fR).
In either case, after proc processdata is finished with an operation that creates a new data set
the result will automatically become the "current data set".
.LP
You can write the results to a file (\fCoutfile\fR) for processing by
other programs, or to read back in and process further using \fBproc getdata\fR
\fCfilter\fR.
.LP
For additional processing capabilities see also
.ig >>
<a href="getdata.html">
.>>
\0proc getdata
.ig >>
</a>
.>>
\fCfilter\fR.
.ig >>
<br><br><br>
.>>
.SH Example
A Gallery example where this is used is
.ig >>
<a href="../gallery/stock.htm">
.>>
\0stock
.ig >>
</a>
.>>
where the available data is in reverse chronological order.
Since lineplot must work from left to right, \fBproc processdata\fR
is used to reverse the record order.
.ig >>
<br><br><br>
.>>
.SH Variables that are set by processdata
.LP
\fBNRECORDS\fR = Number of rows in the data result.
.LP
\fBNFIELDS\fR = Number of fields per row in the data result.
.LP
\fBTOTALS\fR = If totals, percents, or accumulation are being done,
this variable will be set to hold the field total(s). If more than
one field is being operated on, this will be a comma-delimited
list of totals; individual totals may be accessed in your script
using something like the following, which would access the first
total in the list: \fC#set T = $nmember(1,@TOTALS)\fR
.LP
\fBBREAKFIELD1 .. n\fR = Current contents of break fields with \fCaction: breaks\fR
.LP
\fCaction: stats\fR sets a number of other variables, described in the \fCstats\fR section below.
.ig >>
<br><br><br>
.>>
.SH The action attribute
The \fCaction\fR attribute controls the type of operation that will be done.
Often the \fCfields\fR attribute is used to indicate which field(s) are involved.
.ig >>
<br><br>
.>>
.IP \0
\fBaction: accumulate\fR
.ig >>
.>>
Rewrite field as a cumulative series (accumulation).
The field(s) to operate on must be given in the \fCfields\fR attribute.
For example, the data set on the left would be transformed to the one
on the right (\fCfields: 2\fR):
.nf
A21 3 A21 3
A22 5 --> A22 8
A23 2 A23 10
A24 1 A24 11
.fi
.IP \0
\fBaction: breaks\fR
.ig >>
.>>
Perform break processing (the act of passing through an ordered
data set and taking some action when a key field or fields change).
Break processing is significantly more efficient than scanning a data
set multiple times with a \fCselect\fR statement.
The data set must be sorted such that key fields are grouped.
The key field(s) must be specified using the \fCfields\fR attribute.
The \fBBREAKFIELD1 .. n\fR variable(s) will be set to the current contents
of the break field(s). Your script can detect when the entire data set has
been processed by checking
the NRECORDS variable (equal to 0), or the BREAKFIELD1 variable ($strlen of 0).
For more discussion of break processing
.ig >>
<a href="#breaks">
.>>
\0see below.
.ig >>
</a>
.>>
.ig >>
<br><br>
.>>
.IP \0
\fBaction: breakreset\fR
.ig >>
.>>
Reset the "current row" to the beginning of the data set,
for the occasional time when more than one pass through a data set will be done
using \fCaction: breaks\fR .
This is automatically done if a new data set is read by proc getdata.
.ig >>
<br><br>
.>>
.IP \0
\fBaction: count\fR
.ig >>
.>>
Collapse data by counting the number of instances of a key field.
This action can also summate some other field based on a key
field. Input data must be sorted (or at least grouped) on the key field.
Resulting data set will always have two fields.
One or two \fCfields\fR must be specified using the \fCfields\fR attribute.
If one field is specified, the result fields will be 1) key field, 2) count.
For example (\fCfields: 1\fR):
.nf
062698 062698 2
062698 --> 062898 1
062898 070198 3
070198 070498 1
070198
070198
070498
.fi
.IP \0
If two \fCfields\fR are specified, the result fields will be 1) key field, 2) sum
of the numeric contents found in the second specified field.
For example (\fCfields: 1 2\fR):
.nf
062698 4 062698 10
062698 6 --> 062898 3
062898 3 070198 9
070198 2 070498 2
070198 4
070198 3
070498 2
.fi
See also \fCaction: segment\fR and \fCaction: segmentb\fR described below, which are
similar.
A gallery example that uses \fCaction: count\fR is
.ig >>
<a href="../gallery/hitcount.htm">
.>>
\0hitcount
.ig >>
</a>
.>>
.ig >>
<br><br><br>
.>>
.IP \0
\fBaction: join\fR
.ig >>
.>>
Perform a relational join operation. (2.30+)
All records come from the current data set; left side records are selected using the \fCleftselect\fR
attribute and right side records are selected using \fCrightselect\fR.
The records are joined on one or more fields specified in the \fCfields\fR attribute.
The data must be ordered on these fields (integer fields should be ordered numerically; alphanumeric
fields should be ordered alphabetically).
One (and only one) left side record and one (and only one) right side record must exist in order to be joined
(but see leftjoin and rightjoin below).
For example, suppose we want a scatterplot where the X component and Y component
are represented in different sets of records within the data set:
.nf
001 X 4.3 001 X 4.3 001 Y 5.2
001 Y 5.2 --> 002 X 3.2 002 Y 2.9
002 X 3.2
002 Y 2.9
.fi
In order to do a scatterplot of X vs. Y we need to do a join so that all data for case 001 are
on the same row, and all data for case 002 are on the same row. We can do this using:
.nf
#proc processdata
showresults: yes
action: join
fields: 1
leftselect: @@2 = X
rightselect: @@2 = Y
.fi
Also available are \fBaction: leftjoin\fR and \fBaction: rightjoin\fR.
With a left join, if a left side record exists with no right side companion, the right side
is filled in with a missing data code (\fC=\fR by default; can be specified in \fCmissingdatacode\fR
attribute). A right join is the same thing but in reverse.
.ig >>
<br><br><br>
.>>
.IP \0
\fBaction: numberrows\fR
.ig >>
.>>
Prepend a row number field to each row. For example:
.nf
A AA AAA 0 1 A AA AAA 0
B BB BBB 0 ---> 2 B BB BBB 0
C CC CCC 1 3 C CC CCC 1
D DD DDD 1 4 D DD DDD 1
E EE EEE 0 5 E EE EEE 0
F FF FFF 1 6 F FF FFF 1
.fi
.ig >>
<br><br>
.>>
.IP \0
\fBaction: percent\fR
.ig >>
.>>
Rewrite one or more fields as percentages of its field (column) total.
The field(s) to operate on must be given in the \fCfields\fR attribute.
For example (\fCfields: 1\fR):
.nf
8 40
4 --> 20
3 15
5 25
.fi
.ig >>
<br><br>
.>>
.IP \0
\fBaction: reverse\fR
.ig >>
.>>
The last record becomes the first one; the
record order is reversed. For example (\fCfields: 2\fR):
.nf
AXB 34 DIF 14
BYA 22 --> CES 52
CES 52 BYA 22
DIF 14 AXB 34
.fi
.ig >>
<br><br>
.>>
.IP \0
\fBaction: rotate\fR
.ig >>
.>>
First row becomes 1st field, 2nd row
becomes 2nd field, and so on. This may be useful
in that most of the plotting procs work from data fields,
but sometimes data is given (or is more intuitive) in rows.
For example:
.nf
A 2 4 6 8 10 --> A B
B 3 6 9 12 15 2 3
4 6
6 9
8 12
10 15
.fi
.ig >>
<br><br>
.>>
.IP
\fBaction: segment\fR
.ig >>
.>>
Similar to \fCaction: count\fR, except that instead of a count result, a range is produced,
useful for plotting bar segments, etc.
Resulting data set will always have three fields: 1) key field, 2) start position, 3) end position.
.IP
If one \fCfield\fR is specified, the start and end position will be record numbers of the first
and last records in the range (where first record is 1). For example (\fCfields: 1\fR):
.nf
062698 062698 1 3
062698 ---> 070198 4 6
062698 070498 7 7
070198
070198
070198
070498
.fi
If two \fCfields\fR are specified, the start and end position will be the contents of the second
specified field, for the first and last records in the range.
For example (\fCfields: 1 2\fR):
.nf
062698 A 062698 A C
062698 B ---> 070198 D F
062698 C 070498 G G
070198 D
070198 E
070198 F
070498 G
.fi
.IP
\fBaction: segmentb\fR
.ig >>
.>>
Same as \fCaction: segment\fR, except that groups will butt up against one another.
For example (\fCfields: 1 2\fR):
.nf
062698 A 062698 A D
062698 B ---> 070198 D G
062698 C 070498 G G
070198 D
070198 E
070198 F
070498 G
.fi
.ig >>
<br><br>
.>>
.IP \0
\fBaction: stats\fR
.ig >>
.>>
Find the mean, SD, min, max, etc. for data field(s), and put mean, SD, min, max (etc) into ploticus variables.
No new data set is created. Versions 2.30+.
The data field(s) to operate on should specified in the \fCfields\fR attribute.
Sets the following ploticus variables:
.br
\fBMEAN\fR = mean of all numeric values found
.br
\fBSD\fR = standard deviation
.br
\fBN\fR = number of numeric values found
.br
\fBMIN\fR = the lowest numeric value found
.br
\fBMIN_ID\fR = contents of identifier/abscissa field in data row where minima was found
.br
\fBMAX\fR = the highest numeric value found
.br
\fBMAX_ID\fR = contents of identifier/abscissa field in data row where maxima was found
.br
\fBNMISSING\fR = number of non-numeric observations
.br
\fBTOTAL\fR = sum of all numeric values in the field
.IP
(The following is a change in functionality starting in 2.31:)
This action can operate on one data field or several.
The data field(s) to operate on should specified in the \fCfields\fR attribute.
If more than one data field is specified, the data values from all the fields will be examined as
a group and the result will still be a single mean, SD, etc.
\fCtagfield\fR may be specified (see below) to indicate an identifier or abscissa field
which will be used to identify min and max cases (MIN_ID and MAX_ID) and may be useful in annotating
the min and/or max with a later invocation of #proc annotate.
.ig >>
<br><br><br>
.>>
.IP \0
\fBaction: total\fR
.ig >>
.>>
Compute field total(s) only and place total(s) into the variable
TOTALS (see above). No new data set is created.
Field(s) to be totalled are specified in the \fCfields\fR attribute.
.br
The decimal format of the total(s) is controlled by the \fCresultformat\fR
attribute. If total(s) are to be written in presentable notation
(a spacer for thousands, etc.) the \fCresultformat\fR attribute may be
preceded by a \fCn\fR, e.g. \fCn%7.0f\fR.
.ig >>
<br><br><br>
.>>
.SH Other attributes
.LP
\fBfields\fR
.ig >>
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
list
.IP \0
The field(s) to be operated on. Required for any \fCaction\fR that involves
data fields.
.br
Example: \fCfields: 2 5 6 7\fR
.ig >>
<br><br>
.>>
.LP
\fBkeepfields\fR
.ig >>
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
list
.IP \0
If specified, only the listed fields in the original data set
will be kept. The others will be rejected.
\fCaction\fR may be anything.
.br
Example: \fCkeepfields: 4 5 6\fR
.ig >>
<br><br>
.>>
.LP
\fBrejectfields\fR
.ig >>
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
list
.IP \0
If specified, the listed fields in the original data set
will not be kept. The others will be.
\fCaction\fR may be anything.
.br
Example: \fCrejectfields: 1 2 3 4\fR
.ig >>
<br><br>
.>>
.LP
\fBtagfield\fR
.ig >>
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
.IP \0
Used with \fCaction: stats\fR to specify an identifier or abscissa data field,
which will be used to identify min and max cases.
.ig >>
<br><br>
.>>
.LP
\fBfieldnames\fR
.ig >>
.>>
\fInamelist\fR
.IP \0
If specified, result data fields will be assigned the given names.
These names can later be used in any plotting proc to identify data fields.
\fInamelist\fR is a space- or comma- delimited list of names.
Names may include any alphanumeric characters with a maximum length of 38, and are case-insensitive.
.br
Note that if field names are specified in \fBproc getdata\fR
and then \fBproc processdata\fR is used to alter the order of fields or
delete fields, then this \fCfieldnames\fR attribute \fBmust\fR be
used in order to redefine the field names properly.
.br
Example: \fCfieldnames: date group n\fR
.ig >>
<br><br>
.>>
.LP
\fBresultformat\fR
.ig >>
.>>
.ig >>
<a href="attributetypes.html#printfspec">
.>>
\0printf-spec
.ig >>
</a>
.>>
.IP \0
Controls the decimal format of rewritten percents, accumulations, totals.
Default is \fC%g\fR.
.br
Example: \fCresultformat: %f\fR
.br
Example for \fCaction: totals\fR (see above): \fCresultformat: n%g\fR
.ig >>
<br><br>
.>>
.LP
\fBkeepall\fR
.ig >>
.>>
\fCyes\fR | \fCno\fR
.IP \0
If \fCyes\fR, original fields are preserved when doing accumulate, percent, or total.
Thus the result will have more fields than the original data set. Default is \fCno\fR.
.ig >>
<br><br>
.>>
.LP
\fBselect\fR
.ig >>
.>>
.ig >>
<a href="select.html">
.>>
\0selection expression
.ig >>
</a>
.>>
.IP \0
Used when \fCaction\fR is \fCselect\fR in order to specify the selection
condition. Beginning in version 2.20 \fCselect\fR can be used along with
any \fCaction\fR.
.br
Example: \fCselect: @@4 = A\fR
.ig >>
<br><br>
.>>
.LP
\fBstack\fR
.ig >>
.>>
\fCyes\fR | \fCno\fR
.IP \0
The default is \fCyes\fR which causes
the result data set to be "stacked", and the original data set is preserved in memory.
If \fCno\fR, the result data set replaces the original data set in memory (this might
be desired for larger data sets).
.ig >>
<br><br>
.>>
.LP
\fBshowresults\fR
.ig >>
.>>
\fCyes | no\fR
.IP \0
If \fCyes\fR the data are shown after processing, as a diagnostic aid.
.ig >>
<br><br>
.>>
.LP
\fBoutfile\fR
.ig >>
.>>
\fIfilename\fR
.IP \0
If specified, results are written to \fIfilename\fR, in tab-delimited format,
for processing by other programs, or to read back in and process further using
\fBproc getdata\fR \fCfilter\fR.
\fIfilename\fR can be a pathname or \fCstdout\fR or \fCstderr\fR.
Use of this attribute implies \fCstack: no\fR
.ig >>
<br><br>
.>>
.LP
\fBleftselect\fR
.ig >>
.>>
.ig >>
<a href="select.html">
.>>
\0select expression
.ig >>
</a>
.>>
.br
\fBrightselect\fR
.ig >>
.>>
.ig >>
<a href="select.html">
.>>
\0select expression
.ig >>
</a>
.>>
.IP \0
Used with \fCaction: join\fR (and leftjoin, rightjoin).
Specifies selection conditions for left side of join and right side of join.
.ig >>
<br><br>
.>>
.LP
\fBmissingdatacode\fR
.ig >>
.>>
string
.IP \0
Used with \fCaction: leftjoin\fR (and rightjoin) to specify a missing data code to use for
filling in missing fields.
.ig >>
<a name=breaks></a>
.>>
.ig >>
<br><br><br>
.>>
.SH More on break processing
.LP
\fCaction: breaks\fR performs break processing.
In data processing terminology, "break processing" is the act of passing
through a sorted data set and doing something special when a change is encountered in key field(s).
For example, if we were processing a list of charges ordered by paying budget
number, we could use a break processing strategy to pause and generate
a statement for one budget number, when we reached the point in the
data set where the budget numbers changed. Then we would continue on.
\fCaction: breaks\fR allows a similar thing to be done with plotting.
Break processing is significantly more efficient than scanning the entire data
set multiple times with a \fCselect statement\fR, especially with larger data sets.
.LP
The data set must be sorted such that key fields are grouped.
The key field(s) must be specified in the \fCfields\fR attribute.
\fBproc processdata\fR is generally called within a #loop. When \fBproc processdata\fR
finishes, the
.ig >>
<a href="dataformat.html#currentds">
.>>
\0current data set
.ig >>
</a>
.>>
will be the block of data from the previous break to the current break.
\fBproc usedata\fR must be used at the bottom of the loop, to set the
.ig >>
<a href="dataformat.html#currentds">
.>>
\0current data set
.ig >>
</a>
.>>
back to the larger data set that we are passing thru.
Subsequent invocations of \fBproc processdata\fR then continue
from the most recent break location.
.LP
Your script can access the current contents of the break field(s) via the
\fBBREAKFIELD1 .. n\fR variable(s).
Your script can detect when the entire data set has been processed by checking
the NRECORDS variable (equal to 0), or the BREAKFIELD1 variable ($strlen of 0).
The following is an example:
.br
.nf
\0 #loop
\0 #proc processdata
\0 action: breaks
\0 fields: 1 2 3
\0 #proc endproc
\0
\0 #if @NRECORDS = 0
\0 #break
\0 #endif
\0
\0 #proc page
\0 title: Account @BREAKFIELD1
\0
\0 #proc bars
\0 ...
\0
\0 #proc usedata
\0 original: yes
\0
\0 #endloop
.fi
.LP
Limits: up to 5 break fields may be used.
Comparisons for equality are limited to the first 50 characters.
.ig >>
<br>
<br>
</td></tr>
<td align=right>
<a href="../doc/welcome.html">
<img src="../doc/ploticus.gif" border=0></a><br><small>data display engine <br>
<a href="../doc/Copyright.html">Copyright Steve Grubb</a>
<br>
<br>
<center>
<img src="../gallery/all.gif">
</center>
</td></tr>
</table>
<br>
<center>
Ploticus is hosted at http://ploticus.sourceforge.net <br>
<img src="http://sourceforge.net/sflogo.php?group_id=38453" width="88" height="31" border="0" alt="SourceForge Logo">
</center>
.>>
|