home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / bit / listserv / sasl / 3497 < prev    next >
Encoding:
Text File  |  1992-07-30  |  3.0 KB  |  78 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!europa.asd.contel.com!paladin.american.edu!auvm!USCMVSA.BITNET!RROBERT
  3. Message-ID: <SAS-L%92073016291221@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Thu, 30 Jul 1992 13:28:00 PDT
  6. Reply-To:     Bob Roberts <RROBERT@USCMVSA.BITNET>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Bob Roberts <RROBERT@USCMVSA.BITNET>
  9. Subject:      more on nesting data steps
  10. Lines: 66
  11.  
  12. I recently wrote to ask if it was possible to nest data steps in
  13. SAS.  Thanks to those of you who responded.  The consensus is that
  14. it is not possible.
  15.  
  16. Maybe someone can help me out with the original problem that led me
  17. to write in the first place.  The problem stems from having to
  18. examine all possible pairs of observations in a data set
  19. in order to calculate several non-parametric statistics that are
  20. not handled by statistical software packages.
  21. A colleague (Michael Stallings) and I
  22. are attempting to write a SAS program that will allow us to convert
  23. an N x P matrix (N = subjects; P = variables) into a matrix of size
  24. (N(N - 1) X 2P).  The larger matrix contains all possible pairs of
  25. records (each record consists of a set of observations (P) for a
  26. single person).  We have written a program that will convert the
  27. smaller matrix to the larger one.  The problem, of course, is that
  28. when N gets large, the program requires significant computational
  29. resources (e.g., if N = 1000 and P = 20, the larger matrix is of the
  30. order 999,000 by 40).  It's a bit clunky now, but the code is:
  31.  
  32. data first; set zero(keep=id var1 var2 var3) end=eof;
  33. nobs = _N_;
  34. array eins(50) v1-v50;   * N = 50;
  35. einds(nobs) = id;
  36. if end then output;
  37.  
  38. data second; set first(keep=v1-v50 nobs);
  39. array zwei(50) v1-v50;
  40.    do i = 1 to nobs;
  41.       do j = 1 to nobs;
  42.          id1 = zwei(i);
  43.          id2 = zwei(j);
  44.          output;
  45.        end;
  46.       end;
  47. proc sort;
  48.    by id1;
  49.  
  50. data third; merge first(rename=(id=id1)) second (in=intwo) ; by id1;
  51. if intwo;
  52.  
  53. data fourth; set third;
  54. proc sort;
  55.    by id2;
  56.  
  57. data fifth; merge first (rename=(id=id2 var1=avar1 var2=avar2
  58.                                  var3=avar3))
  59.                   fourth (in=infour)
  60.                   by id2;
  61. if infour;
  62. if id1=id2 then delete;
  63.  
  64.  
  65. Because we routinely deal with data sets with large numbers of cases
  66. we are interested in writing a more effecient program.
  67. It turns out that we can achieve the final calculations of interest
  68. to us by pooling results obtained within each of the N matrices
  69. that consist of all possible pairings of subject i with all other
  70. subjects j.  Our strategy was to loop out of the current data step
  71. after we had constructed all pairings for each subject i and (1)
  72. perform the merges required to retrieve the original data for each
  73. subject, (2) perform the calculations required, (3) save the results
  74. to a cummulative file, (4) delete the matrix for subject i, and (5)
  75. return to the next subject in the original data step.  Since looping
  76. in and out of data steps is not possible, we would be interested to
  77. hear if anyone else has ideas about how to solve this problem.
  78.