<?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 A simple word game in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61083#M13266</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. It is very interesting.&lt;/P&gt;&lt;P&gt;Thank FriedEgg who offer me a dictionary , I reserve it,maybe it will be useful for future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data dictionary;
 infile 'c:\unix-words';
 input words : $100.;
run;
%let first=play;
%let last=table;
data _null_;
 length key _key word1 word2 $ 100;
 declare hash ha(hashexp : 20,dataset : 'work.dictionary(rename=(words=key))');
 declare hiter hi('ha');
&amp;nbsp; ha.definekey('key');
&amp;nbsp; ha.definedata('key');
&amp;nbsp; ha.definedone();

 rc=hi.first();
 do while(rc=0);
&amp;nbsp;&amp;nbsp; _key=key; 
&amp;nbsp;&amp;nbsp; word1=cats("&amp;amp;first",_key); key=word1;r1=ha.check();
&amp;nbsp;&amp;nbsp; word2=cats(_key,"&amp;amp;last");key=word2;r2=ha.check();
&amp;nbsp;&amp;nbsp; if r1=0 and r2=0 then do;put 'Found:' word1 word2; found=1;end;
 rc=hi.next();
 end;
 if not found then put 'Search over. Not Found.';
stop;
run;
 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Sep 2011 06:56:23 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-09-09T06:56:23Z</dc:date>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61078#M13261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Create a program that takes two words as input, for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;play&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table&lt;/P&gt;&lt;P&gt;hair&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ball&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program will find linkage words between the two given:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;play/table (playtimes, timestable)&lt;/P&gt;&lt;P&gt;hair/ball (hairpin, pinball)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In unix utilize the dictionary file ( /usr/dict/words or /usr/share/dict/words ) for your seed data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a solution, I wouldn't call it efficient but the code is pretty simple.&amp;nbsp; I will share later in order to give everyone a blank starting point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: I have attached a gunzipped version of the dictionary file to this thread for the non-unix folks...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Sep 2011 19:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61078#M13261</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-09-06T19:48:09Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61079#M13262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it will be easy by using Hash Table.&lt;/P&gt;&lt;P&gt;But without word dictionary&amp;nbsp; /usr/dict/words or /usr/share/dict/words . It is hard to code something.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 02:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61079#M13262</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-09-07T02:59:17Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61080#M13263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS has a built in dictionary.&amp;nbsp; You can find it at sashelp.base.master.dictnary&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 03:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61080#M13263</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-07T03:30:41Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61081#M13264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Really?&lt;/P&gt;&lt;P&gt;How do I use it? Is it a table or view or a file?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 05:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61081#M13264</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-09-07T05:26:56Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61082#M13265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I attached a copy of the dictionary file to my original posting&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 14:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61082#M13265</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-09-07T14:38:35Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61083#M13266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. It is very interesting.&lt;/P&gt;&lt;P&gt;Thank FriedEgg who offer me a dictionary , I reserve it,maybe it will be useful for future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data dictionary;
 infile 'c:\unix-words';
 input words : $100.;
run;
%let first=play;
%let last=table;
data _null_;
 length key _key word1 word2 $ 100;
 declare hash ha(hashexp : 20,dataset : 'work.dictionary(rename=(words=key))');
 declare hiter hi('ha');
&amp;nbsp; ha.definekey('key');
&amp;nbsp; ha.definedata('key');
&amp;nbsp; ha.definedone();

 rc=hi.first();
 do while(rc=0);
&amp;nbsp;&amp;nbsp; _key=key; 
&amp;nbsp;&amp;nbsp; word1=cats("&amp;amp;first",_key); key=word1;r1=ha.check();
&amp;nbsp;&amp;nbsp; word2=cats(_key,"&amp;amp;last");key=word2;r2=ha.check();
&amp;nbsp;&amp;nbsp; if r1=0 and r2=0 then do;put 'Found:' word1 word2; found=1;end;
 rc=hi.next();
 end;
 if not found then put 'Search over. Not Found.';
stop;
run;
 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Sep 2011 06:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61083#M13266</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-09-09T06:56:23Z</dc:date>
    </item>
    <item>
      <title>A simple word game</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61084#M13267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Ksharp for the solution utilizing hash object.&amp;nbsp; It works well.&amp;nbsp; Here is another solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let v1=play;&lt;/P&gt;&lt;P&gt;%let v2=table;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data words(keep=word) word1(keep=word link) word2(keep=word link);&lt;/P&gt;&lt;P&gt; infile '/usr/share/dict/words' truncover;&lt;/P&gt;&lt;P&gt; input word : $45.;&lt;/P&gt;&lt;P&gt; output words;&lt;/P&gt;&lt;P&gt; array v[2] $ 45 _temporary_ ("&amp;amp;v1" "&amp;amp;v2");&lt;/P&gt;&lt;P&gt; do i=1 to dim(v);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if index(word,trim(v&lt;I&gt;))&amp;gt;0 then&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; link=tranwrd(word,trim(v&lt;I&gt;),'');&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count(trim(link),' ')&amp;lt;2 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array l[2] $ 45 _temporary_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to dim(l);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l&lt;J&gt;=scan(trim(link),j,' ');&lt;/J&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if length(l[1])&amp;gt;length(l[2]) then link=l[1]; else link=l[2];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i=1 then output word1; else output word2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table want as&lt;/P&gt;&lt;P&gt; select a.link ,a.word as word1 ,b.word as word2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from ( select strip(link) as link ,word&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from word1&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where link in ( select word from words ) ) a,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ( select strip(link) as link ,word&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from word2&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where link in ( select word from words ) ) b&lt;/P&gt;&lt;P&gt;&amp;nbsp; where a.link=b.link;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My example will not produce the same results.&amp;nbsp; In my original examples of output I made it seem like the words should follow a pattern where a/b -&amp;gt; ac cb but it was unitentional and my solution above allows for more linkages to be found.&amp;nbsp; The hash can be modified to meet the same results, I will do it later if I find the time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Sep 2011 18:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-word-game/m-p/61084#M13267</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-09-09T18:03:42Z</dc:date>
    </item>
  </channel>
</rss>

