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

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!UNC.BITNET!UPHILG
  3. Return-Path: <@OHSTVMA.ACS.OHIO-STATE.EDU:SAS-L@VTVM2.BITNET>
  4. Message-ID: <SAS-L%93012114384991@VTVM2.CC.VT.EDU>
  5. Newsgroups: bit.listserv.sas-l
  6. Date:         Thu, 21 Jan 1993 14:39: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:      reflections on: How to skip variables in SAS
  11. Lines: 58
  12.  
  13. Andrew Karp provided a neat answer for Haiyi Xie's problem of selecting
  14. just a few variables from a raw data file which will be converted into   few
  15. a SAS data set in subequent data analyses, namely:
  16.                                                                          for
  17. DATA CLASS(KEEP=POP71 POP75-POP77 POP85);
  18.    INFILE SOC631.DAT LRECL=320;
  19.         INPUT   #1
  20.                 #2 (POP70-POP85)  (16*20.)
  21.                 #3
  22.                 #4
  23.                 #5
  24.                 #6
  25.                 #7
  26.                 #8
  27.                 #9
  28.                 #10
  29.                 #11
  30.                 #12 ;
  31.                         RUN;
  32.  
  33.     Being unable to resist being my usual picky self, I point out
  34.     that the following will work as well:
  35.  
  36. DATA CLASS(KEEP=POP71 POP75-POP77 POP85);
  37.    INFILE SOC631.DAT LRECL=320;
  38.    INPUT  #2 (POP70-POP85)  (16*20.)
  39.           #12 ;
  40. RUN;
  41.  
  42.      The #n tells SAS to move a pointer to line n;  SAS takes the
  43.      largest value of n to appear in the INPUT stmnt to be the number of
  44.      of lines per case.  In addition, within the n records for a case
  45.      one may move the pointer backward and forward at will, as long as
  46.      the #n (where n is the number of records per case) appears
  47.      somewhere in the stmnt.
  48.  
  49.     Therefore the following works, too:
  50.  
  51. DATA CLASS(KEEP=POP71 POP75-POP77 POP85);
  52.    INFILE SOC631.DAT LRECL=320;
  53.    INPUT  #12  #2 (POP70-POP85)  (16*20.);
  54. RUN;
  55.  
  56.     In principle (al?) this code should be trivially more efficient
  57.     than the original code, for moving the pointer 12 times must take
  58.     a little longer than moving it 2 times - but I would be amazed
  59.     if the savings would be noticeable for anything but a truly
  60.     enormous dataset.  Thus my suggestion is really only trivially
  61.     different from Andrew's.  My hope is that it spotlights the
  62.     mechanism a little better, that's all.
  63.  
  64.  
  65.     I imagine Andrew knows all this and didn't want to unnecessarily
  66.     complicate a reply to a beginner (makes sense to me!), but, as I
  67.     said, I couldn't resist, and Haiyi Xie already has Andrew's
  68.     uncomplicated answer.
  69.  
  70.                                    Phil Gallagher
  71.