BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dio
Calcite | Level 5 dio
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

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

dio
Calcite | Level 5 dio
Calcite | Level 5

Works like a charm, thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 613 views
  • 0 likes
  • 2 in conversation