home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / bit / listserv / sasl / 5770 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.0 KB  |  66 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!uvaarpa!darwin.sura.net!bogus.sura.net!howland.reston.ans.net!paladin.american.edu!auvm!UNC.BITNET!UPHILG
  3. Return-Path: <@OHSTVMA.ACS.OHIO-STATE.EDU:SAS-L@VTVM2.BITNET>
  4. Message-ID: <SAS-L%93012612402902@VTVM2.CC.VT.EDU>
  5. Newsgroups: bit.listserv.sas-l
  6. Date:         Tue, 26 Jan 1993 12:36:00 EST
  7. Reply-To:     "Philip Gallagher,(919)966-1065" <UPHILG@UNC.BITNET>
  8. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  9. From:         "Philip Gallagher,(919)966-1065" <UPHILG@UNC.BITNET>
  10. Subject:      Changing order of variables in a SAS dataset
  11. Comments: cc: ted@SERVER.SASW.NCSU.EDU
  12. Lines: 52
  13.  
  14. Ted Greenstein <TED@SERVER.SASW.NCSU.EDU>
  15.     writes enquiring about changing the order of variables
  16.     in a SAS dataset.  I knew that I didn't know the answer to
  17.     this, for I have never had the need to do it.  I suppose it
  18.     might be useful if one were preparing datasets for students
  19.     who were too naive to use VAR stmnts, or something like that,
  20.     though.  Ted wrote asking for a solution that works for 6.08
  21.     in Windows;  my soln was tested in 5.18, but I hope it will work
  22.     for 6.08 as well.
  23.  
  24.     My first expectation was that clever use of either a KEEP stmnt
  25.     or a KEEP= dataset option would accomplish the re-ordering, but
  26.     I tried it and proved to myself that neither device reordered the
  27.     variables in any of the ways that I implemented them.
  28.  
  29.     Then I resorted to (first) something I knew would work, namely
  30.     creating a dummy (no observations) dataset using a datastep with
  31.     nothing but a LENGTH stmnt in which I ordered the variables in
  32.     the desired order.  Then, I created a new dataset by concatenating
  33.     the old (unwanted order) dataset onto the dummy (desired order)
  34.     dataset, for I knew that SAS would take the order from the first
  35.     dataset it encountered.  This worked.  (I was using 5.18, and
  36.     the resulting concatenation had an unexpect first observation
  37.     of all missing values from the nominally 0 observation dummy
  38.     dataset, and I had to put in a stmnt to delete that observation,
  39.      - unnecessarily nasty complication - I think it is different in
  40.      6.04, but I haven't checked yet.)
  41.  
  42.     Finally I tried using the LENGTH stmnt in a datastep, preceding
  43.     the SET stmnt;  as I expected, everything worked fine.
  44.     Here is the code that produced the final result;  needless to
  45.     say, it is much simpler than producing a dummy dataset and
  46.     concatenating onto it.
  47.  
  48.     I am surprised that the KEEP stmnt/dataset didn't do the
  49.     reordering, but that shows how little I know about how
  50.     the SAS compiler works when it is establishing the characteristics
  51.     of a dataset.  I know a tiny bit more, now.
  52.  
  53.                            Phil Gallagher
  54.                            uphilg@unc
  55.  
  56. DATA NEW;
  57.    ARRAY ZAP {10} var1-var10;
  58.    DO I = 1 TO 10; ZAP{I} = I; END;    drop i;
  59. RUN;
  60. PROC PRINT;  TITLE 'Original order';  run;
  61.  
  62. DATA NEWEST;
  63.     length VAR10 VAR9 VAR8 VAR7 VAR6 VAR5 VAR4 VAR3 VAR2 VAR1 8;
  64.     SET NEW; RUN;
  65. PROC PRINT;  TITLE 'Order via DATAstep LENGTH stmnt';  run;
  66.