home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / bit / listserv / sasl / 5475 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.5 KB  |  55 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Newsgroups: bit.listserv.sas-l
  3. Path: sparky!uunet!gatech!paladin.american.edu!auvm!uvvm!klassen
  4. References:  <01GSFEXYZJCW94DZY5@WIZARD.COLORADO.EDU>
  5. Message-ID: <92358.151515KLASSEN@UVVM>
  6. Date:         Wed, 23 Dec 1992 15:15:15 PST
  7. Reply-To:     Melvin Klassen <KLASSEN@UVVM.BITNET>
  8. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  9. Comments:     Warning -- original Sender: tag was NETNEWS@UVVM.UVIC.CA
  10. From:         Melvin Klassen <KLASSEN@UVVM.BITNET>
  11. Subject:      Re: INDEX function different in DATA step and SCL, V 6.07
  12. Lines: 41
  13.  
  14. "John D. Smith, Info Resrc Mgmt" <smith_jd@ums.colorado.edu> writes:
  15. > A little gotcha for you:
  16. >
  17. > The INDEX function works different in SCL and the DATA step!
  18. > Consider the >following statement:
  19. >     pointer = index(CHARVAR, ' ');
  20. >Produces the following results:
  21. >                            Value of Pointer in
  22. >Value of CHARVAR              SCL        DATA
  23. >TEST IT ALL                    4          4
  24. >TEST                           0          4
  25. >I can think of reasons why the two might behave differently, but I couldn't
  26. >find anything in the FMs that mentions this specifically.  Beware!
  27.  
  28. In the DATA step, the strings 'TEST' and 'TEST IT ALL' may have many
  29. trailing-blanks when stored in the DATA-step variable named 'CHARVAR'.
  30. Therefore, the INDEX function in the DATA step will return '5', in both cases.
  31.  
  32. In SCL, as in the DATA step, different rules for "padding" apply.
  33. See page 218 ("Performing Comparisons") in "SAS(r) Guide to Macro Processing,
  34. Version 6, Second Edition" for the phrase:
  35.    if one string contains fewer characters than the other,
  36.    the shorter string is padded with trailing blanks.
  37.  
  38. Thus, the string 'TEST', when stored in a macro-variable named CHARVAR,
  39. may have either **no** or **some** trailing-blanks. Page 87 (ibid) states:
  40.     %LET macro-variable = <value>;
  41.     where
  42.       <value> is a string, or a macro-expression that yields a string.
  43.       Leading and trailing blanks in _value_ are ignored;
  44.       to make them significant, enclose _value_ in the %STR function.
  45.  
  46. For example:   "%LET CHARVAR = %STR(TEST     );"
  47. is one way to store trailing-blanks into CHARVAR.
  48. Now that CHARVAR contains a "blank", the %INDEX function will find it!
  49.  
  50. The important point is that the macro-processor **automatically**
  51. does what the programmer must **intentionally** code in a DATA step.
  52.  
  53. Consider the different behaviour in SCL and MACRO as "productivity-enhancers",
  54. because the programmer need not write code to strip leading/trailing blanks.
  55.