BookmarkSubscribeRSS Feed
dio
Calcite | Level 5 dio
Calcite | Level 5

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;

1 REPLY 1
dio
Calcite | Level 5 dio
Calcite | Level 5

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1248 views
  • 0 likes
  • 1 in conversation