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!
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.
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.