using a word as delimiter in scan

  • Follow


Hi All,

can i use a word as a delimiter in SCAN

eg:

data xx;
    x = 'using a word as delimiter in scan';
    y = scan(x,1,'in');
run;

i would like the result to be " using a word as delimiter"

but with the above step the result is "us".

i could get the result what i want using other method but is just
curious to know if this could be done in SCAN

Thanks
Rang.
0
Reply rangoon 11/18/2010 4:49:09 PM

On Nov 18, 8:49=A0am, rangoon rangoon <rangoonraja...@gmail.com> wrote:
> Hi All,
>
> can i use a word as a delimiter in SCAN
>
> eg:
>
> data xx;
> =A0 =A0 x =3D 'using a word as delimiter in scan';
> =A0 =A0 y =3D scan(x,1,'in');
> run;
>
> i would like the result to be " using a word as delimiter"
>
> but with the above step the result is "us".
>
> i could get the result what i want using other method but is just
> curious to know if this could be done in SCAN
>
> Thanks
> Rang.

Try use tranwrd to change the delimiter word to a special letter, then
use it for scan:

34   data xx;
35       x =3D 'using a word as delimiter in scan';
36       y =3D scan(tranwrd(x,' in ','~'),1,'~');
37   put x=3D / y=3D;
38   run;

INFO: Character variables have defaulted to a length of 200
      (Line):(Column). Truncation may result.
      36:5     y
x=3Dusing a word as delimiter in scan
y=3Dusing a word as delimiter

Note, the blank before and after is needed to make 'in' a real word.

HTH

Ya
0
Reply Ya 11/18/2010 6:36:15 PM


On Thu, 18 Nov 2010 08:49:09 -0800 (PST), rangoon rangoon
<rangoonraja999@gmail.com> wrote:

>Hi All,
>
>can i use a word as a delimiter in SCAN
>
>eg:
>
>data xx;
>    x = 'using a word as delimiter in scan';
>    y = scan(x,1,'in');
>run;
>
>i would like the result to be " using a word as delimiter"
>
>but with the above step the result is "us".

That is because each character in argument 3 is an independent word
separator.  The 'i' in 'in' separates the "word" us from the "word" g
in the normal word using.  (The n would be ignored since it is a
separator at the start of a "word".)

>
>i could get the result what i want using other method but is just
>curious to know if this could be done in SCAN

Nope.  But you could consider making your own scanwd function (or even
macro) based on Ya's response.

-- 
Remove del for email
0
Reply Barry 11/19/2010 2:32:05 AM

2 Replies
773 Views

(page loaded in 0.129 seconds)

Similiar Articles:













7/22/2012 10:22:21 PM


Reply: