<?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: Kramer matrix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947105#M370819</link>
    <description>&lt;P&gt;Just add one more data step to impute these missing value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));

%macro CRAMV;
	%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
	%do j = &amp;amp;i. %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA ttt; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

PROC APPEND  DATA=ttt BASE=Kramer_All_Way2  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;


data Kramer_All_Way2;
 set Kramer_All_Way2;
 output;
 if var1 ne var2 then do;
   temp=var1;var1=var2;var2=temp;output;
 end;
 drop temp;
run;
proc tabulate data=Kramer_All_Way2;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1728638368703.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101135iFBC43F656A875E8E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1728638368703.png" alt="Ksharp_0-1728638368703.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Oct 2024 09:19:35 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-10-11T09:19:35Z</dc:date>
    <item>
      <title>Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946904#M370784</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to run a code that calculate Kramer correlation matrix between categorical variables.&lt;/P&gt;
&lt;P&gt;I have a question please about improving the code.&lt;/P&gt;
&lt;P&gt;My code check correlation between any pair of variables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my example there are 4 variables&amp;nbsp;X Y Z R so it calculate correlation between:&lt;/P&gt;
&lt;P&gt;X,X&amp;nbsp; &amp;nbsp; X,Y&amp;nbsp; &amp;nbsp;X,Z&amp;nbsp; &amp;nbsp;X,R&lt;/P&gt;
&lt;P&gt;Y,Y&amp;nbsp; &amp;nbsp; Y,X&amp;nbsp; &amp;nbsp;Y,Z&amp;nbsp; &amp;nbsp; Y,R&lt;/P&gt;
&lt;P&gt;Z,Z&amp;nbsp; &amp;nbsp; Z,X&amp;nbsp; &amp;nbsp;Z,Y&amp;nbsp; &amp;nbsp;Z,R&lt;/P&gt;
&lt;P&gt;R,R&amp;nbsp; &amp;nbsp;R,X&amp;nbsp; &amp;nbsp;R,Y&amp;nbsp; &amp;nbsp;R,Z&lt;/P&gt;
&lt;P&gt;So it calculate 16 correlations&lt;/P&gt;
&lt;P&gt;However, correlation of X,Y&amp;nbsp; is same as correlation of Y,X (and so on)&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;How can we improve the code that it will calculate the correlation matrix quicker?&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Another question-&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;I have a warning message -&lt;/P&gt;
&lt;P&gt;WARNING: 31% of the cells have expected counts less than 5, for the table of X&amp;nbsp; by _X &lt;BR /&gt;Chi-Square may not be a valid test.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;What is the way to solve it?&lt;/U&gt;&lt;/STRONG&gt;&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; 
/****categorical Variables list****/
%let list1var=X Y Z R;
%let list2var=&amp;amp;list1var.;

/**Number of varaibles***/
%let n =%sysfunc(countw(&amp;amp;list1var));
%put n=&amp;amp;n; 
%macro CRAMV;
%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
%do j = 1 %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=Raw_Data_tbl;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)/CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA want; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

PROC APPEND  DATA=want BASE=Kramer_All  force;quit;
%end;
%end;
%mend;
%CRAMV;

/***Create matrix***/
title;
ods select all;
proc tabulate data=Kramer_All;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2=''*(_CRAMV_=''*min=''*f=6.5 );
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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it also calculate&amp;nbsp;correlation between:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 05:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946904#M370784</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-10-10T05:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946909#M370785</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output  ChiSq= ChiSq;
PROC FREQ DATA=sashelp.heart(obs=1000);
TABLES (sex status bp_status)*(sex status bp_status)/CHISQ MISSING NOPERCENT NOCOL; 
RUN;
ods select all;
data ChiSq2;
 set ChiSq(where=(Statistic="Cramer's V"));
 row=scan(table,-2,' *');
 col=scan(table,-1,' *');
run;
proc tabulate data=ChiSq2 ;
class row col;
var value;
table row='',col=''*value=''*sum=''*f=6.3;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1728541934202.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101077iB60D473D80B2AB7E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1728541934202.png" alt="Ksharp_0-1728541934202.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;WARNING: 31% of the cells have expected counts less than 5, for the table of X&amp;nbsp; by _X&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chi-Square may not be a valid test."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes. You need EXACT Chisquare Test , Like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FREQ DATA=sashelp.heart(obs=1000);
TABLES sex *status/CHISQ MISSING NOPERCENT NOCOL  ; 
exact chisq  ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 06:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946909#M370785</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-10T06:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946919#M370786</link>
      <description>&lt;P&gt;Thank you so much.&lt;BR /&gt;So as I understand only one change is needed to change&amp;nbsp; chisq to exact chisq.&lt;/P&gt;
&lt;P&gt;(What is the difference in the statistical names? I want to ready the theory)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About my question how to improve running time of kramer matrix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 08:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946919#M370786</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-10-10T08:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946922#M370787</link>
      <description>Yes. But that would cost you lots of time if you have many obs.&lt;BR /&gt;Cramer's V statistic should be the same .but ChiSquare Test would be replace by Exact Fisher Test.&lt;BR /&gt;If you want its theory/algorithm ,check PROC FREQ 's documentation.&lt;BR /&gt;&lt;BR /&gt;"how to improve running time of kramer matrix. "&lt;BR /&gt;What do you mean by that ?  PROC FREQ calculated Cramer's V statistic should have CONSTANT /SAME time interval once the obs number is specified .&lt;BR /&gt;Mine would be faster than yours due to not use macro statement.&lt;BR /&gt;If you really want to get faster ,then you need write your own code(or IML code) to calcuate Cramer's V statistic. and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; might have an interesting to do  that.</description>
      <pubDate>Thu, 10 Oct 2024 08:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946922#M370787</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-10T08:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946928#M370788</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;The question is by using my code ( user define the variables via macro variable) how to cause the code to calculate only one time the correlation between 2 variables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(In my code for example calculated correlation between x&amp;nbsp; and y and then between y and x&amp;nbsp; &amp;nbsp;but they are same...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 09:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946928#M370788</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-10-10T09:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946930#M370789</link>
      <description>&lt;P&gt;You seem to be asking about how to write a macro loop that iterates over (i,j) pairs where i &amp;lt;= j.&amp;nbsp; Look at this example. Hope it helps.&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;%let n = 4;
%macro TRI;
%do i = 1 %to &amp;amp;n.;
   %do j = &amp;amp;i. %to &amp;amp;n.;
      %put &amp;amp;=i, &amp;amp;=j;
   %end;
%end;
%mend;
%TRI;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The key is to start to J loop at &amp;amp;i instead of at 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 10:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/946930#M370789</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-10-10T10:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947079#M370814</link>
      <description>As Rick showed you ,&lt;BR /&gt;using combination ,not permutation :&lt;BR /&gt;&lt;BR /&gt;%do i = 1 %to &amp;amp;n.;&lt;BR /&gt;%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);&lt;BR /&gt;%do j =    %eval(&amp;amp;i.+1)     %to &amp;amp;n.;&lt;BR /&gt;%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);</description>
      <pubDate>Fri, 11 Oct 2024 02:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947079#M370814</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-11T02:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947103#M370818</link>
      <description>&lt;P&gt;I want to summarize the ways to create karmer matrix ,which calculate correlation between categorical variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my original code&amp;nbsp; I calculated the correlation between each pair of variables.&lt;/P&gt;
&lt;P&gt;In the real life with 100,000 rows and 20 variables it took long time ( 10 minutes or more) to run it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I saw how to improve it by calculate only once the correlation between any pair ( so no need to calculate correlation between X and W and W and X. It is enought to calculate only between X and W)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&amp;nbsp; I saw that can calculate the correlation between all variables in one step&amp;nbsp; and it took 1 minute or less to calculate it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you Mr. Ksharp!&lt;/P&gt;
&lt;P&gt;Really big time saving!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***************WAY1---Very slow running time**********************************/
/***************WAY1---Very slow running time**********************************/
/***************WAY1---Very slow running time**********************************/
proc delete data=work._all_;Run;

%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));

%macro CRAMV;
%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
%do j = 1 %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA ttt; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

PROC APPEND  DATA=ttt BASE=Kramer_All_Way1  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;
proc tabulate data=Kramer_All_Way1;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
run;


/***************WAY2---Very slow running time**********************************/
/***************WAY2---Very slow running time**********************************/
/***************WAY2---Very slow running time**********************************/
proc delete data=work._all_;Run;

%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));

%macro CRAMV;
	%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
	%do j = &amp;amp;i. %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA ttt&amp;amp;i.&amp;amp;j.; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

DATA RRR&amp;amp;j.&amp;amp;i.(DROP=VAR1 VAR2  rename=(_VAR2_=VAR2  _VAR1_=VAR1)); 
RETAIN VAR1 VAR2;
SET ttt&amp;amp;i.&amp;amp;j.;
LENGTH VAR1 VAR2 $32.;
_VAR2_ =VAR1;
_VAR1_ =VAR2;
RUN;

Data qqq;
set ttt&amp;amp;i.&amp;amp;j. RRR&amp;amp;j.&amp;amp;i.;
Run;

PROC APPEND  DATA=qqq BASE=Kramer_All_Way2  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;
proc tabulate data=Kramer_All_Way2;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
run;


/****Other way for way2 to fill the matrix with all arguments****/
/****Other way for way2 to fill the matrix with all arguments****/
/****Other way for way2 to fill the matrix with all arguments****/
proc delete data=work._all_;Run;

%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));
%macro CRAMV;
	%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
	%do j = &amp;amp;i. %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;
DATA ttt; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;
PROC APPEND  DATA=ttt BASE=Kramer_All_Way2b  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;

 
data Kramer_All_Way2b;
set Kramer_All_Way2b;
/***Add Rows **/
output;
if var1 ne var2 then do;
temp=var1;
var1=var2;
var2=temp;
output;
end;
drop temp;
run;


proc tabulate data=Kramer_All_Way2b;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
run;


/*****************WAY3---Much better running time!!!*******************/
/*****************WAY3---Much better running time!!!*******************/
/*****************WAY3---Much better running time!!!*******************/
%let list_var=sex status bp_status;
ods select none;
ods output  ChiSq= ChiSq;
PROC FREQ DATA=sashelp.heart;
TABLES (&amp;amp;list_var.)*(&amp;amp;list_var.)/CHISQ MISSING NOPERCENT NOCOL; 
RUN;
ods select all;
data ChiSq2;
set ChiSq(where=(Statistic="Cramer's V"));
row=scan(table,-2,' *');
col=scan(table,-1,' *');
run;
proc tabulate data=ChiSq2 ;
class row col;
var value;
table row='',col=''*value=''*sum=''*f=6.5;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2024 09:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947103#M370818</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-10-11T09:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947105#M370819</link>
      <description>&lt;P&gt;Just add one more data step to impute these missing value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));

%macro CRAMV;
	%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
	%do j = &amp;amp;i. %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA ttt; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

PROC APPEND  DATA=ttt BASE=Kramer_All_Way2  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;


data Kramer_All_Way2;
 set Kramer_All_Way2;
 output;
 if var1 ne var2 then do;
   temp=var1;var1=var2;var2=temp;output;
 end;
 drop temp;
run;
proc tabulate data=Kramer_All_Way2;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1728638368703.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101135iFBC43F656A875E8E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1728638368703.png" alt="Ksharp_0-1728638368703.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 09:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947105#M370819</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-11T09:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Kramer matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947106#M370820</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;The correlation matrix is not full (not all arguments have value) when I apply this method.&lt;/P&gt;
&lt;P&gt;I need to define that Correlation between I and J&amp;nbsp; equal to&amp;nbsp; Correlation between J and I&lt;/P&gt;
&lt;P&gt;I used this way that is working 100%&lt;/P&gt;
&lt;P&gt;Any idea of any other way to fill the all arguments in matrix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1var=sex+status+bp_status;
%let list2var=&amp;amp;list1var.;
%let n =%sysfunc(countw(&amp;amp;list1var));

%macro CRAMV;
	%do i = 1 %to &amp;amp;n.;
%let var1=%scan(&amp;amp;list1var.,&amp;amp;i.,+);
	%do j = &amp;amp;i. %to &amp;amp;n.;
%let var2=%scan(&amp;amp;list2var.,&amp;amp;j.,+);
ods select none;
PROC FREQ DATA=sashelp.heart;
TABLES &amp;amp;VAR1.* (&amp;amp;VAR2.)   /CHISQ MISSING NOPERCENT NOCOL; 
OUTPUT OUT=ttt CRAMV ;
RUN;

DATA ttt&amp;amp;i.&amp;amp;j.; 
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&amp;amp;VAR1";
VAR2 ="&amp;amp;VAR2";
RUN;

DATA RRR&amp;amp;j.&amp;amp;i.(DROP=VAR1 VAR2  rename=(_VAR2_=VAR2  _VAR1_=VAR1)); 
RETAIN VAR1 VAR2;
SET ttt&amp;amp;i.&amp;amp;j.;
LENGTH VAR1 VAR2 $32.;
_VAR2_ =VAR1;
_VAR1_ =VAR2;
RUN;

Data qqq;
set ttt&amp;amp;i.&amp;amp;j. RRR&amp;amp;j.&amp;amp;i.;
Run;

PROC APPEND  DATA=qqq BASE=Kramer_All_Way2  force;
RUN;
%end;
%end;
%mend;
%CRAMV;
title;
ods select all;
proc tabulate data=Kramer_All_Way2;
class  VAR1  VAR2;
var _CRAMV_;
table (VAR1=''),VAR2='' *(_CRAMV_=''*min=''*f=6.5 );
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>Fri, 11 Oct 2024 09:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Kramer-matrix/m-p/947106#M370820</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-10-11T09:19:57Z</dc:date>
    </item>
  </channel>
</rss>

