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