Hi,
i have a problem with the Count function. I would like to specify the substring argument as an element of an array, since i have a list of words and I am looking at the occurences of the words in a list of text. However, it seems like the function fails and only counts when the word appears on the last position in the text. Do you have any idea regarding what I am doing wrong?
Thanks.
/*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 Occurences into a one-dimensional array*/
length occur1-occur3 6;
array occur{3} occur1-occur3;
retain occur1-occur3;
words1="the";
words2="number";
words3="line";
do i=1 to 3;
occur{i}=count(texts,words{i},'i');
end;
/*Define validation variable that uses the typical format of the Count function*/
m=count(texts,"the",'i');
keep texts occur1 m;
run;
Hi,
Since you set the length $20 to your words, they are actually not what they appeared to be, instead, they are the characters+padded blanks all the way to 20.
In this case, you want to ignore blanks by adding modifier 't':
occur{i}=count(texts,words{i},'ti');
And then everything falls back to their place.
BTW, I don't understand why you use length statement at all, since you assign individual values to your words one by one anyway.
Regards,
Haikuo
Hi,
Since you set the length $20 to your words, they are actually not what they appeared to be, instead, they are the characters+padded blanks all the way to 20.
In this case, you want to ignore blanks by adding modifier 't':
occur{i}=count(texts,words{i},'ti');
And then everything falls back to their place.
BTW, I don't understand why you use length statement at all, since you assign individual values to your words one by one anyway.
Regards,
Haikuo
Works like a charm, thanks!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.