<?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 symmetrical matrix with character variable to show diagonal and off diagonal cells in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406612#M279247</link>
    <description>&lt;P&gt;Very nice approach. I like both solutions a great deal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2017 16:13:23 GMT</pubDate>
    <dc:creator>ADouglas</dc:creator>
    <dc:date>2017-10-23T16:13:23Z</dc:date>
    <item>
      <title>Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406105#M279236</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with multiple rows per a unique id. Each row for a given id corresponds to a different level of a qualitative variable called Practice_Area. There are only four practice areas permitted, which are A, B, C, D. See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Practice_Area&lt;/P&gt;&lt;P&gt;123&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;/P&gt;&lt;P&gt;123&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B&lt;/P&gt;&lt;P&gt;123&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;456&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;/P&gt;&lt;P&gt;456&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B&lt;/P&gt;&lt;P&gt;456&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;456&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D&lt;/P&gt;&lt;P&gt;789&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;789&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D&lt;/P&gt;&lt;P&gt;901&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B&lt;/P&gt;&lt;P&gt;901&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/P&gt;&lt;P&gt;901 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a 4x4 symmetrical matrix using SAS to show the number of observations in the off diagonal and diagonal cells. See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp; B&amp;nbsp; C&amp;nbsp; D&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;2&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp; 3&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone post some SAS code to show how this can be done? Thanks !!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406105#M279236</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-20T19:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406111#M279237</link>
      <description>&lt;P&gt;1. Change your data structure via PROC TRANSPOSE to indicate what variables are present in each using 0/1 -&amp;gt; make it look like my test data below.&lt;/P&gt;
&lt;P&gt;2. Use PROC CORR.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id v1-v3;
cards;
11 1 0 1
21 0 2 1
31 1 2 0
41 1 1 0
;
ods output sscp=coocs;
proc corr data=test sscp;
var v1-v3;
run;
proc print data=coocs;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406111#M279237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T19:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406112#M279238</link>
      <description>&lt;P&gt;Maybe it's just the time of day, 10 pm in some minutes, but i don't understand the rules to construct the rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you want the result as dataset or report?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406112#M279238</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-20T19:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406118#M279239</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a report. The cells indicate the number of observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406118#M279239</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-20T19:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406122#M279240</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138057"&gt;@ADouglas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The cells indicate the number of observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;Of what? I'm assuming that means how many ID's have both, ie how many ID's have A, how many ID's have AB, how many ID's have AC&amp;nbsp;etc... primarily all 2 way values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm guessing the question is something like how many people played on X and Y practice area.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I'm guessing...and I don't like to guess &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406122#M279240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406125#M279241</link>
      <description>&lt;P&gt;Yes. You are right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How many in AA, how many in AB, how many in BB, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406125#M279241</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-20T20:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406126#M279242</link>
      <description>&lt;P&gt;Thanks, I will try this soon, and let you know if it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406126#M279242</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-20T20:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406200#M279243</link>
      <description>&lt;P&gt;I can't test this until Monday, but I think it gets you there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;create table pairs&amp;nbsp;as select a.Practice_Area as PA_1, b.Practice_Area as PA_2&lt;/P&gt;
&lt;P&gt;from have a, have b&lt;/P&gt;
&lt;P&gt;where a.id = b.id ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=pairs;&lt;/P&gt;
&lt;P&gt;tables pa_1 * pa_2 / norow nocol nopercent;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;TESTING RESULTS:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;This worked.&amp;nbsp; Got the same results as the solution program.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Other considerations ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;This program generates a report.&amp;nbsp; The solution program generates a data set.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;This program is probably not scalable.&amp;nbsp; The time it would take to generate the Cartesian product on 60K observations might be prohibitive (only one way to find out).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;The solution program turns Practice Area values into variable names.&amp;nbsp; Given the possibility that Practice Area names may be longer than 32 characters, there may be issues to consider (particularly if some Practice Areas are identical for the first 32 characters, but different after that point).&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 15:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406200#M279243</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-23T15:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406232#M279244</link>
      <description>&lt;PRE&gt;
How about this one. But you need SAS/IML.
Otherwise use data step would cost you a lot code.



data have;
input id        Practice_Area $;
cards;
123            A
123            B
123            C
456            A
456            B
456            C
456            D
789            C
789            D
901            B
901            C
901            D
;
run;

data temp;
array x{9999} $ 40 _temporary_;
do i=1 by 1 until(last.id);
  set have;
  by id;
 x{i}=Practice_Area;
end;

do m=1 to i;
 do n=m to i;
   v1=x{m};
   v2=x{n};
   output;
 end;
end;
keep id v1 v2;
run;

proc freq data=temp noprint;
 table v1*v2/out=temp1 list nopercent nocum;
run;

proc transpose data=temp1 out=want(drop=_:);
by v1;
id v2;
var count;
run;

proc iml;
use want;
read all var _num_ into x[c=vname];
read all var {v1};
close;

diag=diag(vecdiag(x));
want=coalesce(t(x),0)+coalesce(x,0)-diag;
print want[c=vname r=v1];
quit;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Oct 2017 12:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406232#M279244</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-21T12:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406234#M279245</link>
      <description>&lt;PRE&gt;
data have;
input id        Practice_Area $;
cards;
123            A
123            B
123            C
456            A
456            B
456            C
456            D
789            C
789            D
901            B
901            C
901            D
;
run;

data temp;
array x{9999} $ 40 _temporary_;
do i=1 by 1 until(last.id);
  set have;
  by id;
 x{i}=Practice_Area;
end;

do m=1 to i;
 do n=m to i;
   v1=x{m};
   v2=x{n};
   output;
   if n ne m then do;
     v2=x{m};
     v1=x{n};
     output;
   end;
 end;
end;
keep id v1 v2;
run;

proc freq data=temp noprint;
 table v1*v2/out=temp1 list nopercent nocum;
run;

proc transpose data=temp1 out=want(drop=_:);
by v1;
id v2;
var count;
run;



&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Oct 2017 12:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406234#M279245</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-21T12:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406253#M279246</link>
      <description>&lt;P&gt;I like this idea. I would like to see if you can get it to work. I will try it too. I never used proc sql statements before. It will be my first. Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 14:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406253#M279246</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-21T14:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406612#M279247</link>
      <description>&lt;P&gt;Very nice approach. I like both solutions a great deal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 16:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406612#M279247</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-23T16:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406619#M279248</link>
      <description>&lt;P&gt;This approach provides the requested solution, but the only drawback is the Percent of Total Frequency variable on the Temp1 dataset. That variable is not needed.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aaron&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 16:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406619#M279248</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-23T16:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406922#M279249</link>
      <description>&lt;PRE&gt;
I think @Astounding get better code.
I don't realize it is a real Cartesian Product .


&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 12:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406922#M279249</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-24T12:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406974#M279250</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am also trying to create a 12x12 symmetrical matrix using 2 column character variables : ID and Disease (categorical, 12 categories)&lt;/P&gt;&lt;P&gt;Each ID may have more than 1 Disease observation&lt;/P&gt;&lt;P&gt;How can I adapt the code above to display (report) a 12x12 matrix (ie. cross-tabulate for co-occurance of the diseases)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following code, but no matrix displays, just a table with 4 colomns (ID, Disease, count, percent) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;array x{9999} $ 40 _temporary_;&lt;BR /&gt;do i=1 by 1 until(last.&lt;STRONG&gt;ID&lt;/STRONG&gt;);&lt;BR /&gt;set sasuser.diseasecat;&lt;BR /&gt;by ID;&lt;BR /&gt;x{i}=&lt;STRONG&gt;Disease&lt;/STRONG&gt;;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do m=1 to i;&lt;BR /&gt;do n=m to i;&lt;BR /&gt;v1=x{m};&lt;BR /&gt;v2=x{n};&lt;BR /&gt;output;&lt;BR /&gt;if n ne m then do;&lt;BR /&gt;v2=x{m};&lt;BR /&gt;v1=x{n};&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;keep &lt;STRONG&gt;ID Disease&lt;/STRONG&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc freq data=temp;&lt;BR /&gt;table IdParticipant*Group/out=temp1 list nopercent nocum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=temp1 out=want(drop=_:);&lt;BR /&gt;by &lt;STRONG&gt;ID&lt;/STRONG&gt;;&lt;BR /&gt;id &lt;STRONG&gt;Disease&lt;/STRONG&gt;;&lt;BR /&gt;var count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=temp1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 15:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406974#M279250</guid>
      <dc:creator>dmarks</dc:creator>
      <dc:date>2017-10-24T15:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406978#M279251</link>
      <description>&lt;P&gt;The matrix output I&amp;nbsp;desire should look like this ideally :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disease A&amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp;D........L&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; 56&amp;nbsp; &amp;nbsp; 29&amp;nbsp; 14&amp;nbsp; &amp;nbsp; &amp;nbsp; 63&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56&amp;nbsp; &amp;nbsp; 100&amp;nbsp; 36&amp;nbsp; &amp;nbsp; 18&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; 36&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&amp;nbsp; &amp;nbsp; 18&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 63&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 15:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406978#M279251</guid>
      <dc:creator>dmarks</dc:creator>
      <dc:date>2017-10-24T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406984#M279252</link>
      <description>Type 12 values of 9 in the array statement.&lt;BR /&gt;&lt;BR /&gt;The 9 functions as a placeholder for each category.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Oct 2017 15:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406984#M279252</guid>
      <dc:creator>ADouglas</dc:creator>
      <dc:date>2017-10-24T15:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406996#M279254</link>
      <description>&lt;P&gt;Thank-you for your reply ADouglas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have typed 14 x the value 9 into the code :&lt;/P&gt;&lt;P&gt;&lt;EM&gt;array x{99999999999999} $ 40 _temporary_;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;but still no matrix appears. My output remains in Table form, as if each ID now had only 1 Disease obervation :&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Disease&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;COUNT&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;PERCENT&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_240&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_12&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;36&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.19177&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_241&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_10&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;25&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.13318&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_242&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;16&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.08523&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_243&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;81&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.43149&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_244&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_5&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;4&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.02131&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID_245&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_6&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;36&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.19177&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;7&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;PART_150168&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GRP_12&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;9&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.04794&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is my code correct for the TRANSPOSE step ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=temp1 out=want(drop=_:);&lt;/P&gt;&lt;P&gt;by IdParticipant;&lt;/P&gt;&lt;P&gt;id Disease;&lt;/P&gt;&lt;P&gt;var count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 16:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/406996#M279254</guid>
      <dc:creator>dmarks</dc:creator>
      <dc:date>2017-10-24T16:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/407230#M279255</link>
      <description>&lt;PRE&gt;
Just change the variable name .
Why not use @Astounding 's code ? I think he have a better code.



data have;
input id       Disease $;
cards;
123            A
123            B
123            C
456            A
456            B
456            C
456            D
789            C
789            D
901            B
901            C
901            D
;
run;

data temp;
array x{9999} $ 40 _temporary_;
do i=1 by 1 until(last.id);
  set have;
  by id;
 x{i}=Disease;
end;

do m=1 to i;
 do n=m to i;
   v1=x{m};
   v2=x{n};
   output;
   if n ne m then do;
     v2=x{m};
     v1=x{n};
     output;
   end;
 end;
end;
keep id v1 v2;
run;

proc freq data=temp noprint;
 table v1*v2/out=temp1 list nopercent nocum;
run;

proc transpose data=temp1 out=want(drop=_:);
by v1;
id v2;
var count;
run;

&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 12:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/407230#M279255</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-25T12:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a symmetrical matrix with character variable to show diagonal and off diagonal cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/407311#M279256</link>
      <description>&lt;P&gt;Thanks for your reply Ksharp.&lt;/P&gt;&lt;P&gt;I have tried to use&amp;nbsp;@Astounding's code to create&amp;nbsp; a matrix for my 2 variables &lt;STRONG&gt;ID&lt;/STRONG&gt; and &lt;STRONG&gt;Disease&lt;/STRONG&gt; :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table matrix&lt;BR /&gt;as select a.&lt;STRONG&gt;Disease&lt;/STRONG&gt; as pa_1, b.&lt;STRONG&gt;Disease&lt;/STRONG&gt; as pa_2&lt;BR /&gt;from sasuser.disease&lt;BR /&gt;where a.&lt;STRONG&gt;IdParticipant&lt;/STRONG&gt; = b.&lt;STRONG&gt;IdParticipant&lt;/STRONG&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc freq data=matrix;&lt;BR /&gt;tables pa_1*pa_2 / norow nocol nopercent;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However i receive the following error message :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;185 where a.ID = b.ID;&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name a.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name a.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;186 quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is my code correct ?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-symmetrical-matrix-with-character-variable-to-show/m-p/407311#M279256</guid>
      <dc:creator>dmarks</dc:creator>
      <dc:date>2017-10-25T14:48:03Z</dc:date>
    </item>
  </channel>
</rss>

