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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1152 views
  • 0 likes
  • 1 in conversation