title: Count number of times a word appears
body: <p>I'm looking for a better way in SAS to count the number of times a certain word appears in a string.  Example, searching for 'wood' in the string:</p>
  
  <pre><code>how much wood could a woodchuck chuck if a woodchuck could chuck wood
  </code></pre>
  
  <p>... would return a result of <code>2</code>.</p>
  
  <p>This is how I would normally do it but it's a lot of code:</p>
  
  <pre><code>data _null_;
    length sentence word $200;
  
    sentence = 'how much wood could a woodchuck chuck if a woodchuck could chuck wood';
    search_term = 'wood';
    found_count = 0;
  
    cnt=1;
    word = scan(sentence,cnt);
    do while (word ne '');
      num_times_found = sum(num_times_found, word eq search_term);
      cnt = cnt + 1;
      word = scan(sentence,cnt);
    end;
  
    put num_times_found=;
  
  run;
  </code></pre>
  
  <p>I can put this into an <code>fcmp</code> function to make it more elegant but I still feel like there must be friendlier and more concise code for this.</p>