From: xiang@milton.u.washington.edu (Charlene Zhu)
Subject: My toughest SAS job
Reply-To: xiang@u.washington.edu
Organization: University of Washington, Seattle
Date: Tue, 29 Sep 1992 17:57:10 GMT

  The following is a very small part of a SAS data file. The raw data
was generated by a dental machine. It took a lot of doing to make it 
so organized. But the next task is even harder: I need to process the 
data conditionally, create new variables based on it, and come out 
with a summary sheet. Because the file is too large, I deleted most
of the obs.

  Part I: Please pay attention to staircase, time, rate, stimulation,and respl.
Within each staircase, I need to come out with one observation with
the following variables: tooth, staircase, beginning-time, ending-time,
detection-threshold, pain-threshold, average-respl, and number-of-errors. 
Where:

	beginning-time=the time the first "0" rate occurs within the 
			staircase;
	ending-time=the time at rate "2" within the same staircase;
	detection-threshold=the average stimulation between the last
			"0" and the first "1" rate in the same staircase,
			in normal cases, such as in staircase #1;
	pain-threshold=the average stimulation between the last "1"
			and the "2" rate in the same staircase,
			in normal cases;
	average-respl=mean of respl for all "1" and "2" rate;
 	number-of-errors=not to worry about at this point.

  So in staircase #1, the new observation would be:
Tooth	Staircase Begin-time  Ending-time  Detect-thres.  Pain-thres. Ave-resp 
0	1	   0.004      1.127        47.5    	   76.0       582 

  I hope you havn't confused yet :)

  Part II: in staircases where some abnormality occurs, there are certain
rules to follow. For example,
  In staircase #19, everything is the same EXCEPT the values for Pain-thres.
It is the average of the highest stimulation for "1" rate and "2" rate,
which is(65+66)/2=65.5.
  In staircase #24, the detection-threshold is the average stimulation
for the rate sequence:"01101", which is (52+55+58+64+65)/5. The same
rule applies to detection-threshold for staircase #27, which is 
(43+46+48+52)/4. Also to staircase #51, (39+41+44+47+49+52)/6. Also
to staircase #52, (45+50+55+61)/4.
  For staircase #48, the detection is the average stimul of obs 799 and
800, which is (48+51)/2. Obs 804 where an abnormal "0" occurred should
be counted as an error.
  For staircase #47, the pain threshold is the average stimul for the
highest "1" and "2", which is obs 791 and 793, (85+87)/2.

  I'm tired with describing all of these. And I know you are tired too.
If you have good ideas, please respond to my private email at:
xiang@u.washington.edu. I'll summarize and post the results here.

  Thank you very much for your expertise and generous help!

Charlene 

  OBS	Tooth   Staircase    Time    Stimulation     Rate     RespL   Impedance

 1 	 0         1       0.004         0            0         -1      0.000
 2	 0         1       0.494         5            0         -1      0.000
 4	 0         1       0.624        20            0         -1     -1.000
 7	 0         1       0.369        45            0         -1      0.384
 8	 0         1       0.847        45            0         -1      0.506
 9	 0         1       0.888        50            1        770      0.406
 10	 0         1       0.933        55            1        522      0.383
 12	 0         1       1.051        68            1        338      0.393
 13	 0         1       1.089        74            1        344      0.435
 14	 0         1       1.127        78            2        354      0.421
 304     0         19      12.792         0            0         -1      0.000
 306     0         19      12.884        10            0         -1      0.000
 309     0         19      13.025        25            0         -1      0.758
 310     0         19      13.073        30            0         -1      0.743
 312     0         19      13.154        40            0         -1      0.491
 313     0         19      13.200        45            1        756      0.504
 314     0         19      13.239        50            1        367      0.438
 316     0         19      13.335        58            1          0      0.436
 317     0         19      13.377        60            1        498      0.495
 318     0         19      13.464        65            2       2483      0.483
 319     0         19      13.425        66            1        430      0.448
 389     1         24      16.427        35            0         -1      0.621
 391     1         24      16.511        41            0         -1      0.487
 393     1         24      16.599        47            0         -1      0.526
 395     1         24      16.695        52            0         -1      0.475
 396     1         24      16.738        55            1        505      0.494
 397     1         24      16.788        58            1        365      0.519
 398     1         24      16.870        64            0         -1      0.517
 399     1         24      16.833        65            1        430      0.500
 400     1         24      16.917        73            1        418      0.522
 402     1         24      16.993        80            1          0      0.528
 403     1         24      17.028        84            1        408      0.535
 404     1         24      17.077        94            2        445      0.536
 442     0         27      18.700         30           0         -1      0.699
 445     0         27      18.828         38           0         -1      0.512
 446     0         27      18.864         40           0         -1      0.487
 447     0         27      18.898         43           0         -1     -1.000
 448     0         27      18.933         46           1        800      0.493
 449     0         27      18.972         48           0         -1      0.462
 450     0         27      19.014         52           1        392      0.496
 451     0         27      19.099         54           1        382      0.508
 453     0         27      19.140         64           1        359      0.483
 455     0         27      19.221         72           1        363      0.491
 456     0         27      19.269         75           2        464      0.481
 775     1         47      32.802        31            0         -1      0.703
 777     1         47      32.896        36            0         -1      0.577
 781     1         47      33.072        45            0         -1      0.532
 782     1         47      33.111        48            0         -1      0.528
 783     1         47      33.153        50            0         -1      0.520
 784     1         47      33.194        52            1        861      0.502
 786     1         47      33.291        56            1        421      0.542
 788     1         47      33.372        67            1        508      0.536
 790     1         47      33.454        79            1        507      0.534
 791     1         47      33.594        85            2        592      0.545
 792     1         47      33.552        86            1        874      0.540
 793     1         47      33.504        87            1        919      0.533
 794     1         48      33.641        34            0         -1      0.568
 796     1         48      33.712        39            0         -1      0.514
 797     1         48      33.754        42            0         -1      0.517
 799     1         48      33.846        48            0         -1      0.490
 800     1         48      33.888        51            1        667      0.504
 801     1         48      33.929        54            1          0      0.485
 802     1         48      34.019        58            1        418      0.541
 803     1         48      33.977        60            1        368      0.517
 804     1         48      34.058        67            0         -1      0.526
 805     1         48      34.099        73            1        405      0.515
 806     1         48      34.140        73            1        361      0.535
 807     1         48      34.188        82            1          0      0.537
 808     1         48      34.236        89            1        420      0.540
 809     1         48      34.282        99            2        373      0.554
 843     0         51      35.723        29            0         -1      1.020
 844     0         51      35.764        31            0         -1      0.593
 845     0         51      35.814        34            0         -1      0.555
 846     0         51      35.860        36            0         -1      0.552
 847     0         51      35.896        39            0         -1      0.554
 848     0         51      35.938        41            1       1104      0.494
 849     0         51      35.983        44            0         -1      0.478
 850     0         51      36.020        47            1        781      0.487
 851     0         51      36.055        49            0         -1      0.472
 852     0         51      36.091        52            1        490      0.484
 853     0         51      36.126        52            1        560      0.450
 854     0         51      36.172        64            1        414      0.467
 856     0         51      36.293        79            1        498      0.514
 860     1         52      36.409         0            0         -1      0.000
 861     1         52      36.451         5            0         -1      0.000
 864     1         52      36.566        20            0         -1     20.770
 867     1         52      36.693        35            0         -1      0.541
 868     1         52      36.729        40            0         -1      0.525
 869     1         52      36.774        45            0         -1      0.527
 870     1         52      36.818        50            1        753      0.482
 871     1         52      36.867        55            0         -1      0.526
 872     1         52      36.915        61            1        519      0.516
 873     1         52      36.951        70            1        375      0.512
 874     1         52      36.989        80            1        402      0.526
 875     1         52      37.036        84            1        752      0.527
 876     1         52      37.078        92            2        550      0.549