Help using Base SAS procedures

array issue with FINDW

Reply
Occasional Contributor dio
Occasional Contributor
Posts: 8

array issue with FINDW

Hi,

i seem to not be able to specify the word argument of the FINDW function as an array. I have a list of words and I am trying to find the position of these words in a list of texts with the FINDW function and the 'E' modifier. However, the function returns position 0 when i specify the word argument and the output variable as arrays, whereas it works perfectly fine in its typical form. Would really appreciate your ideas on why this goes wrong.

Thanks a lot!

/*Example*/

DATA Example;

INPUT Texts $CHAR60.;

DATALINES;

The number of times "the" appears is the question

THE the

None on this line

There is the map

;

DATA Example;

set Example;

/* Load Words into a one-dimensional array*/

length words1-words3 $20;

array words{3} words1-words3;

retain words1-words3;

/* Load position of word into a one-dimensional array*/

length posw1-posw3 6;

array posw{3} posw1-posw3;

retain posw1-posw3;

words1="the";

words2="number";

words3="line";

do i=1 to 3;

   posw{i}=findw(texts,words{i},' ','E');

end;

/*Define validation variable that uses the typical format of the FINDW function*/

m=findw(texts,"the",' ','E');

keep texts posw1 m;

run;

Occasional Contributor dio
Occasional Contributor
Posts: 8

array issue with FINDW

Ok, just realized what the problem was. I had forgot to trim the word...Now it works.

/*Example*/

DATA Example;

INPUT Texts $CHAR60.;

DATALINES;

The number of times "the" appears is the question

THE the

None on this line

There is the map

;

DATA Example;

set Example;

/* Load Words into a one-dimensional array*/

length words1-words3 $20;

array words{3} words1-words3;

retain words1-words3;

/* Load position of word into a one-dimensional array*/

length posw1-posw3 6;

array posw{3} posw1-posw3;

retain posw1-posw3;

words1="the";

words2="number";

words3="line";

do i=1 to 3;

   posw{i}=findw(texts,trim(words{i}),' ','E');

end;

/*Define validation variable that uses the typical format of the FINDW function*/

m=findw(texts,"the",' ','E');

keep texts posw1 m;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 178 views
  • 0 likes
  • 1 in conversation