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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.