Full-Name: Kevin Nechodom (Unix Wannabe)
Organization: U of U CSSRD/STACC
Plan: To get a CS degree before I die.
Censored-By: UofU Thought Police
Mailer: Elm [revision: 70.30]
Newsgroups: bit.listserv.sas-l
Date:         Wed, 16 Dec 1992 22:51:10 MST
Reply-To:     knechod@stacc.med.utah.edu
From:         "Kevin Nechodom (Unix Wannabe)" <knechod@STACC.MED.UTAH.EDU>
Subject:      Re: Multi-liine INPUT formatting (thanks much!)
Comments: To: SAS Mailing List <sas-l@uga.cc.uga.edu>

I would like to thank Bob Upson, J. Philip Miller, Jay Jacob Wind and
Michael T. Weaver for showing me the way to true happiness - at least
as far as data inputting goes!  I was extremely boggled by the fact
that I'm dealing with about 150 different record formats, and their
suggestions were most helpful.

Here's a small sample of the file (120K+ records):
EU01010479000000011982113019830318198508081198302081                         VS
EU010104790000000219821130        198508082                                  VS
EU01010479001000031982113019830318198508082                                  VS

Record 000.01  IDB entry data
 01 -  18  Key values
    01 - 02   Study ID
    03 - 04   Clinic #
    05 - 10   Patient #
    11 - 13   Visit Number
    14 - 16   Card type
    17 - 18   Card sub-type
 19 -  26  FORM DATE                       IDB'FDATE
 27 -  34  DATE RECEIVED                   IDB'DTREC    ccyymmdd
 35 -  42  DATE ENTERED                    IDB'DTENT    ccyymmdd
 43 -  43  ACCEPTED                        IDB'ACCPT    1=Accepted, 2=Rejected
 44 -  51  DATE ACCEPTED/REJECTED          IDB'DTACC    ccyymmdd
 52 -  52  Have received consent form?     IDB'CNSNT    1=Yes, 2=No, 9=N/A
 78 -  80  ENTRY CLERK                     IDB'INITS
Record 000.02  DBE entry data
 01 -  18  Key values
 19 -  26  DATE OF FORM                    DBE'FDATE    ccyymmdd
 35 -  42  DATE ENTERED                    DBE'DTENT    ccyymmdd
 43 -  43  HAS PATIENT DIED                DBE'DTHYN    1=Yes, 2=No
 78 -  80  ENTRY PERSON'S INITIALS         DBE'INITS
Record 000.03  VIS entry data
 01 -  18  Key values
 19 -  26  Visit date                      VIS'FDATE
 27 -  34  DATE RECEIVED                   VIS'DTREC
 35 -  42  Visit date entered              VIS'DTENT    ccyymmdd
 43 -  43  IS THIS WITHDRAWAL VISIT        VIS'WITHV    1=Yes, 2=No, 9=N/A
 78 -  80  Visit entry person's initials   VIS'INITS

And here's the end result:
data local.alldata;
   infile "./bigdump.dat" eof=lasttime lrecl=80 pad;
   attrib studyid  length=$2 label= "Study ID";
   attrib clinum   length=3 informat = 2. format = 2. label= "Clinic Number";
   attrib regnum   length=4 informat = 6. format = 6. label= "Registry Number";
   attrib visnum   length=3 informat = 3. format = 3. label= "Visit Number";
   attrib cardtype length=4 informat = 5. format = 5. label= "Card Type";
   input studyid $ 1-2 clinumhd 3-4 regnumhd 5-10 visnumhd 11-13
         cardtype 14-18 @;
   if clinum = clinumhd and regnum = regnumhd and visnum = visnumhd then do;
      /* each record has its own cardtype id (out of 150, I did 3!) */
      if cardtype = 00001 then do;
         attrib IDBFDATE length= $8 label="Form Date";
         attrib IDBDTREC length= $8 label="Date Received";
         attrib IDBDTENT length= $8 label="Date Entered";
         attrib IDBACCPT length= $1 label="Accepted";
         attrib IDBDTACC length= $8 label="Date Accepted/Rejected";
         attrib IDBCNSNT length= $1 label="Have received consent form?";
         attrib IDBINITS length= $3 label="Entry clerk";
         input  IDBFDATE $19-26 IDBDTREC $27-34 IDBDTENT $35-42 IDBACCPT $43-43
                IDBDTACC $44-51 IDBCNSNT $52-52 IDBINITS $78-80;
         retain IDBFDATE IDBDTREC IDBDTENT IDBACCPT IDBDTACC IDBCNSNT
                IDBINITS;
         return;
         end;
      else if cardtype = 00002 then do;
         attrib DBEFDATE length= $8 label="Date of Form";
         attrib DBEDTENT length= $8 label="Date entered";
         attrib DBEDTHYN length= $8 label="Has patient died";
         attrib DBEINITS length= $8 label="Entry person's initials";
         input  DBEFDATE $19-26 DBEDTENT $35-42 DBEDTHYN $43-43 DBEINITS $78-80;
         retain DBEFDATE DBEDTENT DBEDTHYN DBEINITS;
         return;
         end;
      else if cardtype = 00003 then do;
         attrib VISFDATE length= $8 label="Visit Date";
         attrib VISDTREC length= $8 label="Date Received";
         attrib VISDTENT length= $8 label="Visit Date Entered";
         attrib VISWITHV length= $1 label="Is this Withdrawal Visit";
         attrib VISINITS length= $3 label="Visit entry person's initials";
         input  VISFDATE $19-26 VISDTREC $27-34 VISDTENT $35-42 VISWITHV $43-43
                VISINITS $78-80;
         retain VISFDATE VISDTREC VISDTENT VISWITHV VISINITS;
         return;
         end;
      end;
   else do;
      drop clinumhd regnumhd visnumhd cardtype i;
      if clinum = clinumhd then output;
      array charvars {*} _character_;
      do i=1 to dim(charvars);
        charvars(i) = " ";
        end;
      clinum = clinumhd;
      regnum = regnumhd;
      visnum = visnumhd;
      input @@;
      retain studyid clinum regnum visnum;
      end;
   return;
   /* flush the last record */
   lasttime: output;
run;

Fortunately, the guy I'm working with is a perl wizard, and he has
a report of each card type that he can slice-n-dice.

Thanks again for the helpful suggestions, and for being there when I
needed you!

--
Kevin
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU