A odd result about indexw function.

  • Follow


Dear SAS-Lers,

    I find some interesting thing about indexw function.

    why I get the odd result.

  data a;
  length string $20;
  string='BBSI_EXT_0_COMMENT';
  pos=indexw(upcase(string),'COMMENT','_');
  put pos=;
  run;


I got "pos=0".

if i use    string='BBSI_EXT_0_COMMENT_';

it's ok.




thanks a lot.






2010-01-26



jiyuan123
0
Reply jiyuan123 (6) 1/26/2010 12:52:33 AM

String has a length of 20.  You set it to a constant of length 18.  Therefore, there a two trailing blanks.  Since blank is not a separator in your call to indexw, 'COMMENT  ' does not match 'COMMENT'. You could try
    pos=indexw(strip(string),'COMMENT','_');
and see if that does what you want.

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jiyuan123
Sent: Monday, January 25, 2010 4:53 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: A odd result about indexw function.

Dear SAS-Lers,

    I find some interesting thing about indexw function.

    why I get the odd result.

  data a;
  length string $20;
  string='BBSI_EXT_0_COMMENT';
  pos=indexw(upcase(string),'COMMENT','_');
  put pos=;
  run;


I got "pos=0".

if i use    string='BBSI_EXT_0_COMMENT_';
0
Reply barry.a.schwarz (608) 1/26/2010 1:07:38 AM


hi barry,

   thanks for your help.
   I got it.

best.
jiyuan.




On Mon, 25 Jan 2010 17:07:38 -0800, Schwarz, Barry A
<barry.a.schwarz@BOEING.COM> wrote:

>String has a length of 20.  You set it to a constant of length 18.
Therefore, there a two trailing blanks.  Since blank is not a separator in
your call to indexw, 'COMMENT  ' does not match 'COMMENT'. You could try
>    pos=indexw(strip(string),'COMMENT','_');
>and see if that does what you want.
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
jiyuan123
>Sent: Monday, January 25, 2010 4:53 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: A odd result about indexw function.
>
>Dear SAS-Lers,
>
>    I find some interesting thing about indexw function.
>
>    why I get the odd result.
>
>  data a;
>  length string $20;
>  string='BBSI_EXT_0_COMMENT';
>  pos=indexw(upcase(string),'COMMENT','_');
>  put pos=;
>  run;
>
>
>I got "pos=0".
>
>if i use    string='BBSI_EXT_0_COMMENT_';
0
Reply jiyuan123 (6) 1/26/2010 8:53:33 AM

2 Replies
244 Views

(page loaded in 0.05 seconds)


Reply: