home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!europa.asd.contel.com!paladin.american.edu!auvm!CEHIEC1.EM.CDC.GOV!SPJ1
- Encoding: 69 TEXT
- X-Mailer: Microsoft Mail V3.0 (beta-2)
- Message-ID: <2A9A23A0@router.em.cdc.gov>
- Newsgroups: bit.listserv.sas-l
- Date: Tue, 25 Aug 1992 16:07:00 EST
- Reply-To: SPJ1@CEHIEC1.EM.CDC.GOV
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: SPJ1@CEHIEC1.EM.CDC.GOV
- Subject: Repeated error-checking - a solution
- Comments: To: SAS-L%UGA.BITNET@UGA.CC.UGA.EDU
- Lines: 63
-
- Anne Liang writes:
-
- >Hi, everyone
- >
- >I had a questionaire designed to ask for multiple-response to
- >a single question. There are 10 possible item to choose, identified as
- >a,b,c,....,j. And it takes 10 columns in the rawdata file. For example,
- >if one observation responds with a,c,e it will appear as "ace" in the
- >first three columns with 7 spaces following.
- >The problem is : I must check if the "ace" is mistyped as "acc"(i.e.
- >the repeating error).
- >
- >Any idea/suggestion is much appreciated.
- >
- >Anne Liang at Taipei Taiwan
- >
- >
-
- Here's how I solved your problem:
-
- 114
- 115 data char ;
- 116 input @1 answers $10. ;
- 117 cards;
- 120 ;
- NOTE: The data set WORK.CHAR has 2 observations and 1 variables.
- NOTE: The DATA statement used 2.00 seconds.
- 121 run;
- 122
- 123 data temp2;
- 124 set char ;
- 125 length lookchar $1 whatleft $9 ;
- 126 bad=0 ;
- 127 do i = 1 to length(answers)-1 ;
- 128 whatleft = substr(answers,i+1,length(answers)-i);
- 129 lookchar=substr(answers,i,1);
- 130 if index(whatleft,lookchar) gt 0 then bad=1 ;
- 131 put i= answers= lookchar= whatleft= bad= ;
- 132 end ;
- 133 run;
- I=1 ANSWERS=ace LOOKCHAR=a WHATLEFT=ce BAD=0
- I=2 ANSWERS=ace LOOKCHAR=c WHATLEFT=e BAD=0
- I=1 ANSWERS=acefc LOOKCHAR=a WHATLEFT=cefc BAD=0
- I=2 ANSWERS=acefc LOOKCHAR=c WHATLEFT=efc BAD=1
- I=3 ANSWERS=acefc LOOKCHAR=e WHATLEFT=fc BAD=1
- I=4 ANSWERS=acefc LOOKCHAR=f WHATLEFT=c BAD=1
- NOTE: The data set WORK.TEMP2 has 2 observations and 5 variables.
- NOTE: The DATA statement used 3.00 seconds.
-
- Essentially what you're doing is grabbing a character, and then looking
- at the remaining characters to see if there is a match. If there is,
- INDEX(...) > 0. There are some ways to fancy the code up, but this gives
- the general gist of what you need to do. You'll want to change it to meet
- your specific needs.
-
- Steve James
- ---------------------------------------------------------------------------
- Name Steve James The new computer's a piece
- Mail Address SPJ1@CEHIEC1.EM.CDC.GOV of junk, I'd really wish
- Real address Centers for Disease Control they'd sell it. It never
- 1600 Clifton Road NE, Mailstop F36 does a thing I want, only
- Atlanta, GA 30333 what I tell it.
- (404) 488-4656 Author Unknown
-