<?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: Creating a frequency matrix/table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278938#M56166</link>
    <description>works perfectly, thank you!</description>
    <pubDate>Tue, 21 Jun 2016 08:21:18 GMT</pubDate>
    <dc:creator>myname</dc:creator>
    <dc:date>2016-06-21T08:21:18Z</dc:date>
    <item>
      <title>Creating a frequency matrix/table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278930#M56164</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks pretty much like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input word $ article ;
datalines;
word1, 123456
word2, 123456
word3, 123456
word4, 123456
word5, 123456
word1, 234567
word2, 234567
word3, 234567
word5, 234567
word1, 345678
word3, 345678
word6, 345678
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, I want to know which word appears with another word in how many articles. For example word1 and word2 appear&amp;nbsp;2 times together, word1 and word3 3 times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	word1	word2	word3	word4	word5	word6
  word1   3	2	3	1	2	1
  word2   2	2	2	1	2	0
  word3   3	3	3	1	2	1	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want to generate should look like this or similar, you get the idea &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have tried this for a long time now, but everything I managed just resulted in error messages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there some easy way to do it? Or do you have an idea how I could approach the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 07:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278930#M56164</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-21T07:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a frequency matrix/table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278936#M56165</link>
      <description>&lt;P&gt;If you want symmetry Matrix :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input word $ article ;
datalines;
word1, 123456
word2, 123456
word3, 123456
word4, 123456
word5, 123456
word1, 234567
word2, 234567
word3, 234567
word5, 234567
word1, 345678
word3, 345678
word6, 345678
;
run;
data temp;
array x{9999} $ 50 _temporary_;
length a b $ 50;

do i=1 by 1 until(last.article);
 set have;
 by article;
 x{i}=word;
end;

do m=1 to i-1;
 do n=m+1 to i;
  a=x{m};b=x{n};output;
  a=x{n};b=x{m};output;
 end;
end;
keep a b;
run;
proc sql;
create table levels as
 select a.word as a length=50,b.word as b length=50
 from 
 (select distinct word from have) as a,
 (select distinct word from have) as b
  order by 1,2;
quit;
proc tabulate data=temp classdata=levels;
class a b;
table a='',b=''*n=''/misstext='0';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jun 2016 08:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278936#M56165</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-21T08:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a frequency matrix/table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278938#M56166</link>
      <description>works perfectly, thank you!</description>
      <pubDate>Tue, 21 Jun 2016 08:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278938#M56166</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-21T08:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a frequency matrix/table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278940#M56167</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Odd request. &amp;nbsp;Not sure what you want to do when words are missing. &amp;nbsp;This bit of code gets you the combinations of words from the list, maybe elaborate a bit more on the problem if this doesn't get you there.&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines dsd;
  input word $ article ;
datalines;
word1, 123456
word2, 123456
word3, 123456
word4, 123456
word5, 123456
word1, 234567
word2, 234567
word3, 234567
word5, 234567
word1, 345678
word3, 345678
word6, 345678
;
run;

proc transpose data=have out=t_have;
  by article;
  var word;
  id word;
run;

data want (keep=combination);
  set t_have (drop=article _name_);
  array word{*} word:;
  do i=1 to dim(word)-1;
    combination=catx('/',word{i},word{i+1});
    output;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jun 2016 08:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-frequency-matrix-table/m-p/278940#M56167</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-21T08:22:17Z</dc:date>
    </item>
  </channel>
</rss>

