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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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