<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Ngram modal in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326570#M72746</link>
    <description>&lt;P&gt;I don't see a question here &amp;nbsp;But if you are asking about how to correct your program to get all three-word combinations, here are a few small changes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data test3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set test;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nitems=countw(sen);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;length combo $ 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if nitems &amp;gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do i=1 to nitems&lt;FONT color="#FF0000"&gt;-2&lt;/FONT&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = scan(sen,i);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do j=i+1 to nitems&lt;FONT color="#FF0000"&gt;-1&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do k=j+1 to nitems;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j), scan(sen,k));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jan 2017 13:16:28 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-01-22T13:16:28Z</dc:date>
    <item>
      <title>Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326562#M72741</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wants to creat a ngarm modal, created 3garm modal and the codes are below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;sen = "The cow jumps over the moon";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test3;&lt;BR /&gt;set test;&lt;BR /&gt;nitems=countw(sen);&lt;BR /&gt;length combo $ 100;&lt;BR /&gt;if nitems &amp;gt;1;&lt;BR /&gt;do i=1 to nitems;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = scan(sen,i);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do j=i+1 to nitems;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do k=j+1 to nitems;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j), scan(sen,k));&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2017 10:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326562#M72741</guid>
      <dc:creator>ashish2016sahu</dc:creator>
      <dc:date>2017-01-22T10:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326570#M72746</link>
      <description>&lt;P&gt;I don't see a question here &amp;nbsp;But if you are asking about how to correct your program to get all three-word combinations, here are a few small changes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data test3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set test;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nitems=countw(sen);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;length combo $ 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if nitems &amp;gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do i=1 to nitems&lt;FONT color="#FF0000"&gt;-2&lt;/FONT&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = scan(sen,i);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do j=i+1 to nitems&lt;FONT color="#FF0000"&gt;-1&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#FF0000"&gt;*&lt;/FONT&gt;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;do k=j+1 to nitems;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;combo = catx('', scan(sen,i), scan(sen,j), scan(sen,k));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2017 13:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326570#M72746</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-22T13:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326610#M72770</link>
      <description>&lt;P&gt;I&amp;nbsp;thought ngrams were CONTIGUOUS words, but you are apparently trying to get all word COMBINATIONS (i.e. even if the "ngram" elements are not contiguous).&amp;nbsp; Is that really your intention?&amp;nbsp; (And&amp;nbsp;you say you want "3grams" but you're also outputing single words, and pairs or words.&amp;nbsp;&amp;nbsp;If combinations is what you really want, I'd suggest using the ALLCOMBI function (code untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=ix_:);
  set have;
  item_count=countw(sen);
  if item_count&amp;lt;3 then delete;

  length combo $80;

  array items{20} $12 _temporary_;
  do I=1 to item_count;
    items{I}=scan(sen,I,' ');
  end;

  array ix3 {*} ix_1-ix_3;
  array ix2 {*} ix_1-ix_2;
  array ix1 {*} ix_1-ix_1;


  do combosize=1 to 3;
    ncomb=comb(item_count,combosize);
    ix_1=.;
    do c=1 to ncomb;
      select (combosize);
        when (1) call allcombi(item_count,combosize, of ix1{*});
        when (2) call allcombi(item_count,combosize, of ix2{*});
        when (3) call allcombi(item_count,combosize, of ix3{*});
      end;
      combo=' ';
      do I=1 to combosize;
        combo=catx(' ',combo,items{ix3{I}});
      end;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you only want what it typically defined as ngrams, it's a lot simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;

  item_count=countw(sen);
  length gram $36;

  if item_count&amp;gt;=3 then do g=1 to item_count;
    gram=scan(sen,g,' ');    /*1-gram*/
    output;
    if g=item_count then leave;

    gram=catx(' ',gram,scan(sen,g+1,' '));  /*bi-gram*/
    output;
    if g=item_count-1 then leave;

    gram=catx(' ',gram,scan(sen,g+2,' ');  /*tri-gram*/
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 11:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326610#M72770</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-23T11:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326674#M72802</link>
      <description>Above mentioned coded is giving me this result for a string "The cow jumps over the moon". In combination of Two words:&lt;BR /&gt;&lt;BR /&gt;The cow&lt;BR /&gt;The jumps&lt;BR /&gt;The over&lt;BR /&gt;The the&lt;BR /&gt;The Moon&lt;BR /&gt;cow jumps&lt;BR /&gt;cow over&lt;BR /&gt;cow the&lt;BR /&gt;cow moon&lt;BR /&gt;jumps over&lt;BR /&gt;jumps the&lt;BR /&gt;jumps moon&lt;BR /&gt;over the&lt;BR /&gt;over moon&lt;BR /&gt;the moon&lt;BR /&gt;&lt;BR /&gt;but here the requirement is to get the dynamic combination for n-words like there should be combinations of twos, threes, fours....ns words (all permutation and combinations) so please help me to write a macro for the same.&lt;BR /&gt;&lt;BR /&gt;I hope, am making sense this time.</description>
      <pubDate>Mon, 23 Jan 2017 10:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326674#M72802</guid>
      <dc:creator>ashish2016sahu</dc:creator>
      <dc:date>2017-01-23T10:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326680#M72806</link>
      <description>&lt;P&gt;The program I suggested, after correcting a typographical error, generates singles, doubles, and triples with no coding logic change.&amp;nbsp; So I do not undertand why you got pairs and not triples (the error I corrected is not related to size of combinations).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have now changed your requirement from generating triples (a fixed size)&amp;nbsp;to a variable combination size. You can modify the program to accomodate a larger fixed size.&amp;nbsp; You can do combos up to 10 words with:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (1) adding arrays statements for each size up to 10,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (2) change "do combosize=1 to 3"&amp;nbsp; to "do combosize=1 to min(10,item_count)";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (3) add a "when" statement&amp;nbsp;for each additional size&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (4) change &lt;FONT face="Courier New"&gt;combo=catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,combo,items{ix3{I}});&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to &lt;FONT face="Courier New"&gt;combo=catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,combo,items{ix10{I}});&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in the end, this program is not meant to&amp;nbsp;accomodate ANY size.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 11:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326680#M72806</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-23T11:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Ngram modal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326690#M72809</link>
      <description>&lt;P&gt;A macro-ized version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  sen='the cow jumps over the moon'; 
run; 

%macro want(max=10); 
  %local max /*maximum combination size*/ 
         S   /*combo size index        */ ; 

  data want (drop=ix_:); 
    set have; 
    item_count=countw(sen); 
    if item_count&amp;lt;3 then delete; 

    length combo $%eval(100+&amp;amp;max*13); 

    array items{&amp;amp;max} $12 _temporary_; 
    do I=1 to min(item_count,&amp;amp;max); 
      items{I}=scan(sen,I,' '); 
    end; 

    %do S=1 %to &amp;amp;max; 
      array ix&amp;amp;S {*} ix_1-ix_&amp;amp;S ; 
    %end; 

    do combosize=1 to item_count; 
      ncomb=comb(item_count,combosize); 
      ix_1=.; 
      do c=1 to ncomb;
        select (combosize);
        %do s=1 %to &amp;amp;max ;
          when(&amp;amp;S) call allcombi(item_count,combosize,of ix&amp;amp;S{*});
        %end;
        end;
        combo=' ';
        do I=1 to combosize;
          combo=catx(' ',combo,items{ix&amp;amp;max{I}});
        end;
        output;
      end;
    end;

  run;
  %mend;

%want(max=15);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I said earlier, the program is not meant for a variable combination size, which is why it now has to be macro-ized.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 12:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ngram-modal/m-p/326690#M72809</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-23T12:22:54Z</dc:date>
    </item>
  </channel>
</rss>

