home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / bit / listserv / sasl / 3877 < prev    next >
Encoding:
Text File  |  1992-08-25  |  2.9 KB  |  78 lines

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