<?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: Little's MCAR Macro in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414258#M21727</link>
    <description>&lt;P&gt;The macro came from here:&amp;nbsp;&amp;nbsp;&lt;A href="http://www.appliedmissingdata.com/macro-programs.html" target="_self"&gt;http://www.appliedmissingdata.com/macro-programs.html&lt;/A&gt;&amp;nbsp;and I've pasted it below.&lt;/P&gt;&lt;P&gt;I've&amp;nbsp; using various syntax for calling in the data as the code in the macro for that, specifically&lt;/P&gt;&lt;PRE&gt;%let datafile = "c:\data\eatingrisk.dat"; &lt;/PRE&gt;&lt;P&gt;created errors.&amp;nbsp; Thank you for your help!&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;/******************************************************************************************************************/&lt;BR /&gt;* *&lt;BR /&gt;* This SAS macro implements the chi-square test for a missing completely at random (MCAR) mechanism, as *&lt;BR /&gt;* outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or higher) because *&lt;BR /&gt;* PROC MI is used to obtain ML estimates of the covariance matrix and mean vector. * *&lt;BR /&gt;* *&lt;BR /&gt;/******************************************************************************************************************/;&lt;/P&gt;&lt;P&gt;%macro mcartest;&lt;/P&gt;&lt;P&gt;/* SPECIFY FILE PATH FOR THE INPUT DATA */&lt;BR /&gt;%let DATA = WORK.Newtwo;&lt;/P&gt;&lt;P&gt;/* SPECIFY INPUT DATA VARIABLE LIST */&lt;/P&gt;&lt;P&gt;%let varlist = Age&lt;BR /&gt;Began&lt;BR /&gt;Track&lt;BR /&gt;BioGender&lt;BR /&gt;Minority&lt;BR /&gt;GRE&lt;BR /&gt;GPA&lt;BR /&gt;CSES_Total_Ori&lt;BR /&gt;CSES_Total_Prac&lt;BR /&gt;CSES_Total_Intern&lt;BR /&gt;mnrty_2&lt;BR /&gt;mnrty_3&lt;BR /&gt;mnrty_1&lt;BR /&gt;mnrty_4&lt;BR /&gt;mnrty_5&lt;BR /&gt;mnrty_6;&lt;/P&gt;&lt;P&gt;/* SPECIFY VARIABLE SET FOR THE MCAR TEST */&lt;/P&gt;&lt;P&gt;%let testvars =&lt;BR /&gt;GRE&lt;BR /&gt;GPA&lt;BR /&gt;CSES_Total_Ori&lt;BR /&gt;CSES_Total_Prac&lt;BR /&gt;CSES_Total_Intern;&lt;/P&gt;&lt;P&gt;/* SPECIFY THE MISSING VALUE CODE */&lt;BR /&gt;&lt;BR /&gt;%let misscode = .;&lt;BR /&gt;&lt;BR /&gt;/*******************************/&lt;BR /&gt;/* DO NOT ALTER THE CODE BELOW */&lt;BR /&gt;/*******************************/&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;infile &amp;amp;datafile ;&lt;BR /&gt;input &amp;amp;varlist;&lt;/P&gt;&lt;P&gt;%let numvars = %sysfunc(countw(&amp;amp;testvars));&lt;/P&gt;&lt;P&gt;array m[&amp;amp;numvars] &amp;amp;testvars ;&lt;BR /&gt;array r[&amp;amp;numvars] r1 - r&amp;amp;numvars ;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;numvars;&lt;BR /&gt;if m[i] = &amp;amp;misscode then m[i] = .;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;numvars;&lt;BR /&gt;r[i] = 1;&lt;BR /&gt;if m[i] = . then r[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt;by r1-r&amp;amp;numvars;&lt;/P&gt;&lt;P&gt;proc mi data = one nimpute = 0 noprint;&lt;BR /&gt;var &amp;amp;testvars;&lt;BR /&gt;em outem = emcov;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;use one;&lt;BR /&gt;read all var {&amp;amp;testvars} into y;&lt;BR /&gt;read all var {%do i = 1 %to &amp;amp;numvars; r&amp;amp;i %end;} into r;&lt;BR /&gt;use emcov;&lt;BR /&gt;read all var {&amp;amp;testvars} into em;&lt;/P&gt;&lt;P&gt;mu = em[1,];&lt;BR /&gt;sigma = em[2:nrow(em),];&lt;/P&gt;&lt;P&gt;/* ASSIGN AN INDEX VARIABLE DENOTING EACH CASE'S PATTERN */&lt;/P&gt;&lt;P&gt;jcol = j(nrow(y), 1 , 1);&lt;/P&gt;&lt;P&gt;do i = 2 to nrow(y);&lt;BR /&gt;rdiff = r[i,] - r[i - 1,];&lt;BR /&gt;if max(rdiff) = 0 &amp;amp; min(rdiff) = 0 then jcol[i,] = jcol[i - 1,];&lt;BR /&gt;else jcol[i,] = jcol[i - 1,] + 1;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* NUMBER OF DISTINCT MISSING DATA PATTERNS */&lt;/P&gt;&lt;P&gt;j = max(jcol);&lt;/P&gt;&lt;P&gt;/* PUT THE NUMBER OF CASES IN EACH PATTERN IN A COL VECTOR M */&lt;BR /&gt;/* PUT THE MISSING DATA INDICATORS FOR EACH PATTERN IN A MATRIX RJ */&lt;/P&gt;&lt;P&gt;m = j(j, 1, 0);&lt;BR /&gt;rj = j(j, ncol(r), 0);&lt;/P&gt;&lt;P&gt;do i = 1 to j;&lt;BR /&gt;count = 0;&lt;BR /&gt;do k = 1 to nrow(y);&lt;BR /&gt;if jcol[k,] = i then do;&lt;BR /&gt;count = count + 1;&lt;BR /&gt;end;&lt;BR /&gt;if jcol[k,] = i &amp;amp; count = 1 then rj[i,] = r[k,];&lt;BR /&gt;m[i,] = count;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* COMPUTE D^2 STATISTIC FOR EACH J PATTERN */&lt;/P&gt;&lt;P&gt;d2j = j(j, 1, 0);&lt;/P&gt;&lt;P&gt;do i = 1 to j;&lt;/P&gt;&lt;P&gt;/* OBSERVED VALUES FOR PATTERN J */&lt;/P&gt;&lt;P&gt;yj = y[loc(jcol = i),loc(rj[i,] = 1)];&lt;/P&gt;&lt;P&gt;/* VARIABLE MEANS FOR PATTERN J */&lt;/P&gt;&lt;P&gt;ybarobsj = yj[+,]/nrow(yj);&lt;/P&gt;&lt;P&gt;/* D = P X Pj MATRIX OF INDICATORS (SEE P. 1199) */&lt;/P&gt;&lt;P&gt;Dj = j(ncol(y), rj[i,+], 0);&lt;/P&gt;&lt;P&gt;count = 1;&lt;BR /&gt;do k = 1 to ncol(rj);&lt;BR /&gt;if rj[i,k] = 1 then do;&lt;BR /&gt;Dj[k, count] = 1;&lt;BR /&gt;count = count + 1;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* REDUCE EM ESTIMATES TO CONTAIN OBSERVED ELEMENTS */&lt;/P&gt;&lt;P&gt;muobsj = mu * Dj;&lt;BR /&gt;sigmaobsj = t(Dj) * sigma * Dj;&lt;/P&gt;&lt;P&gt;/* THE CONTRIBUTION TO THE D^2 STATISTIC FOR EACH OF THE J PATTERNS */&lt;/P&gt;&lt;P&gt;d2j[i,] = m[i,] * (ybarobsj - muobsj) * inv(sigmaobsj) * t(ybarobsj - muobsj);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;/* THE D^2 STATISTIC */&lt;/P&gt;&lt;P&gt;d2 = d2j[+,];&lt;/P&gt;&lt;P&gt;/* DF FOR D^2 */&lt;/P&gt;&lt;P&gt;df = rj[+,+] - ncol(rj);&lt;BR /&gt;p = 1 - probchi(d2,df);&lt;/P&gt;&lt;P&gt;/* PRINT ANALYSIS RESULTS */&lt;/P&gt;&lt;P&gt;file print;&lt;BR /&gt;put "Number of Observed Variables = " (ncol(rj)) 3.0;&lt;BR /&gt;put "Number of Missing Data Patterns = " (j) 3.0; put;&lt;BR /&gt;put "Summary of Missing Data Patterns (0 = Missing, 1 = Observed)"; put;&lt;BR /&gt;put "Frequency | Pattern | d2j"; put;&lt;BR /&gt;do i = 1 to nrow(rj);&lt;BR /&gt;put (m[i,]) 6.0 " | " @;&lt;BR /&gt;do j = 1 to ncol(rj);&lt;BR /&gt;put (rj[i,j]) 2.0 @;&lt;BR /&gt;end;&lt;BR /&gt;put " | " (d2j[i,]) 8.6;&lt;BR /&gt;end;&lt;BR /&gt;put;&lt;BR /&gt;put "Sum of the Number of Observed Variables Across Patterns (Sigma psubj) = " (rj[+,+]) 5.0; put;&lt;BR /&gt;put "Little's (1988) Chi-Square Test of MCAR"; put;&lt;BR /&gt;put "Chi-Square (d2) = " (d2) 10.3;&lt;BR /&gt;put "df (Sigma psubj - p) = " (df) 7.0;&lt;BR /&gt;put "p-value = " (p) 10.3;&lt;/P&gt;&lt;P&gt;%mend mcartest;&lt;BR /&gt;%mcartest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 05:27:07 GMT</pubDate>
    <dc:creator>dhahs</dc:creator>
    <dc:date>2017-11-17T05:27:07Z</dc:date>
    <item>
      <title>Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403608#M21046</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please provide working macro for Little MCAR Test in SAS. The Macro which is already there , contains stack of errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attaching snippet of error and code i have used to run Base Sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bharat&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 16:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403608#M21046</guid>
      <dc:creator>BharatKoti</dc:creator>
      <dc:date>2017-10-12T16:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403614#M21047</link>
      <description>&lt;P&gt;When dealing with macros you want to set:&lt;/P&gt;
&lt;P&gt;Options MPRINT SYMBOLGEN;&lt;/P&gt;
&lt;P&gt;and then run the macro.&lt;/P&gt;
&lt;P&gt;Post the LOG with code and the resulting diagnostics into a code box opened using the forum {I} menu icon to preserve plain text formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You mentioned something about a "snippet of error" but that wasn't included in the attachment.&lt;/P&gt;
&lt;P&gt;You may also need to describe what this is actually supposed to do. I'm not interested in running what a "Little MCAR Test" may require in terms of your data set or calculations.&lt;/P&gt;
&lt;P&gt;Did your source for this macro include any information about the data requirements? Did you verify that your data met those requirements?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 16:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403614#M21047</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-12T16:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403616#M21048</link>
      <description>&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Sorry for missing the attachment. To check whether missingness in dataset is due to MCAR , ran the macro code which was there on the net. I have the data set in the required format to run the macro. I am new to running macros, it would be of great help if you could me on the same. Please find attached data set which is an input data for macro. Thanks in advance.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mcar Error" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15826iDC488D9F8CE1EB98/image-size/large?v=v2&amp;amp;px=999" role="button" title="Mcar Error.PNG" alt="Mcar Error" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Mcar Error&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;%macro mcartest;
/* PROVIDE VALUES FOR THE FOLLOWING MACRO VARIABLES */
%let datafile = "C:\Users\Bharat\Desktop\7037 Project\hbat_missing_new"; * FILE PATH FOR RAW DATA;
%let numvars = 26; * NUMBER OF VARS IN DATA FILE;
%let misscode = .; * SPECIFY MISSING VALUE CODE;
%let varnames = v1_miss v2_miss v3_miss v4_miss v5_miss; * SPECIFY VARIABLE NAMES;
%let seednum = 564321; * SPECIFY RANDOM SEED;
/* DO NOT ALTER THE CODE BELOW */
data one;
infile &amp;amp;datafile ;
input &amp;amp;varnames ;
array m[&amp;amp;numvars] &amp;amp;varnames ; array r[&amp;amp;numvars] r1 - r&amp;amp;numvars ;
do i = 1 to &amp;amp;numvars;
if m[i] = &amp;amp;misscode then m[i] = .;
end; drop i;
do i = 1 to &amp;amp;numvars;
r[i] = 1;
if m[i] = . then r[i] = 0;
21
end; drop i;
proc sort;
by r1-r&amp;amp;numvars;
proc mi data = one seed = &amp;amp;seednum nimpute = 0 noprint;
var &amp;amp;varnames;
em outem = emcov;
proc iml;
use one; read all var {&amp;amp;varnames} into y;
read all var {%do i = 1 %to &amp;amp;numvars; r&amp;amp;i %end;} into r;
use emcov; read all var {&amp;amp;varnames} into em;
mu = em[1,]; sigma = em[2:nrow(em),];
/* ASSIGN AN INDEX VARIABLE DENOTING EACH CASE’S PATTERN */
jcol = j(nrow(y), 1 , 1);
do i = 2 to nrow(y);
rdiff = r[i,] - r[i - 1,];
if max(rdiff) = 0 &amp;amp; min(rdiff) = 0 then jcol[i,] = jcol[i - 1,];
else jcol[i,] = jcol[i - 1,] + 1;
end;
/* NUMBER OF DISTINCT MISSING DATA PATTERNS */
j = max(jcol);
/* PUT THE NUMBER OF CASES IN EACH PATTERN IN A COL VECTOR M */ /*
PUT THE MISSING DATA INDICATORS FOR EACH PATTERN IN A MATRIX RJ */
m = j(j, 1, 0); rj = j(j, ncol(r), 0);
do i = 1 to j;
count = 0;
do k = 1 to nrow(y);
if jcol[k,] = i then do;
count = count + 1;
end;
22
if jcol[k,] = i &amp;amp; count = 1 then rj[i,] = r[k,];
m[i,] = count;
end;
end;
/* COMPUTE D^2 STATISTIC FOR EACH J PATTERN */
d2j = j(j, 1, 0);
do i = 1 to j;
/* OBSERVED VALUES FOR PATTERN J */
yj = y[loc(jcol = i),loc(rj[i,] = 1)];
/* VARIABLE MEANS FOR PATTERN J */
ybarobsj = yj[+,]/nrow(yj);
/* D = P X Pj MATRIX OF INDICATORS (SEE P. 1199) */
Dj = j(ncol(y), rj[i,+], 0);
count = 1; do k = 1 to ncol(rj);
if rj[i,k] = 1 then do;
Dj[k, count] = 1;
count = count + 1;
end;
end;
/* REDUCE EM ESTIMATES TO CONTAIN OBSERVED ELEMENTS */
muobsj = mu * Dj; sigmaobsj = t(Dj) * sigma * Dj;
/* THE CONTRIBUTION TO THE D^2 STATISTIC FOR EACH OF THE J PATTERNS
*/
d2j[i,] = m[i,] * (ybarobsj - muobsj) * inv(sigmaobsj) * t(ybarobsj
- muobsj);
end;
23
/* THE D^2 STATISTIC */
d2 = d2j[+,];
/* DF FOR D^2 */
df = rj[+,+] - ncol(rj); p = 1 - probchi(d2,df);
/* PRINT ANALYSIS RESULTS */
file print; put "Number of Observed Variables = " (ncol(rj)) 3.0;
put "Number of Missing Data Patterns = " (j) 3.0; put; put "Summary
of Missing Data Patterns (0 = Missing, 1 = Observed)"; put; put
"Frequency | Pattern | d2j"; put; do i = 1 to nrow(rj);
put (m[i,]) 6.0 " | " @;
do j = 1 to ncol(rj);
put (rj[i,j]) 2.0 @;
end;
put " | " (d2j[i,]) 8.6;
end; put; put "Sum of the Number of Observed Variables Across
Patterns (Sigma psubj) = " (rj[+,+]) 5.0; put; put "Little’s (1988)
Chi-Square Test of MCAR"; put; put "Chi-Square (d2) = " (d2)
10.3; put "df (Sigma psubj - p) = " (df) 7.0; put "p-value
= " (p) 10.3;
%mend mcartest;
%mcartest;
run;


&lt;/PRE&gt;&lt;P&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 16:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403616#M21048</guid>
      <dc:creator>BharatKoti</dc:creator>
      <dc:date>2017-10-12T16:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403618#M21049</link>
      <description>I wasn't able to upload the data set file , as it threw an error and said data type isn't supported</description>
      <pubDate>Thu, 12 Oct 2017 16:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403618#M21049</guid>
      <dc:creator>BharatKoti</dc:creator>
      <dc:date>2017-10-12T16:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403634#M21051</link>
      <description>&lt;P&gt;In the body of the code:&lt;/P&gt;
&lt;PRE&gt;r[i] = 1;
if m[i] = . then r[i] = 0;
21                                  /*&amp;lt;= this is not valid code, likely a line number from somewhere, remove the 21*/
end; drop i;
&lt;/PRE&gt;
&lt;P&gt;You also apparently have incomplete data, the error about "too few variables" says that something is expecting more variables than you supplied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 17:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403634#M21051</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-12T17:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403636#M21052</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171285"&gt;@BharatKoti&lt;/a&gt; wrote:&lt;BR /&gt;I wasn't able to upload the data set file , as it threw an error and said data type isn't supported&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 17:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403636#M21052</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-12T17:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403656#M21053</link>
      <description>&lt;P&gt;Where ever you got that macro from (copy and paste from PDF???) garbled the text somehow, messing up the macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find a better source.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.appliedmissingdata.com/littles-mcar-test.sas" target="_blank"&gt;http://www.appliedmissingdata.com/littles-mcar-test.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's also old, you may want to look at PROC MI.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/multiple-imputation-in-sas/mi_new_1/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/multiple-imputation-in-sas/mi_new_1/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 19:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/403656#M21053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-12T19:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414210#M21724</link>
      <description>&lt;P&gt;I'm trying to run the code from this site to test Little's MCAR: &lt;A href="http://www.appliedmissingdata.com/littles-mcar-test.sas" target="_self"&gt;http://www.appliedmissingdata.com/littles-mcar-test.sas&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am continuing to get errors.&amp;nbsp; I have tried redefining the datafile name based on other suggestions I have seen online, however nothing seems to be solving the problem. I'm pasting the code and output I get below. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1 /**********************************************************************************************&lt;BR /&gt;1 ! ********************/&lt;BR /&gt;2 *&lt;BR /&gt;2 ! *&lt;BR /&gt;3 * This SAS macro implements the chi-square test for a missing completely at random (MCAR)&lt;BR /&gt;3 ! mechanism, as *&lt;BR /&gt;4 * outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or&lt;BR /&gt;4 ! higher) because *&lt;BR /&gt;5 * PROC MI is used to obtain ML estimates of the covariance matrix and mean vector.&lt;BR /&gt;5 ! * *&lt;BR /&gt;6 *&lt;BR /&gt;6 ! *&lt;BR /&gt;7 /**********************************************************************************************&lt;BR /&gt;7 ! ********************/;&lt;BR /&gt;8&lt;BR /&gt;9 %macro mcartest;&lt;BR /&gt;10&lt;BR /&gt;11 /* SPECIFY FILE PATH FOR THE INPUT DATA */&lt;BR /&gt;12 DATA = WORK.Newtwo;&lt;BR /&gt;13&lt;BR /&gt;14 /* SPECIFY INPUT DATA VARIABLE LIST */&lt;BR /&gt;15&lt;BR /&gt;16 %let varlist = Age&lt;BR /&gt;17 Began&lt;BR /&gt;18 Track&lt;BR /&gt;19 BioGender&lt;BR /&gt;20 Minority&lt;BR /&gt;21 GRE&lt;BR /&gt;22 GPA&lt;BR /&gt;23 CSES_Total_Ori&lt;BR /&gt;24 CSES_Total_Prac&lt;BR /&gt;25 CSES_Total_Intern&lt;BR /&gt;26 mnrty_2&lt;BR /&gt;27 mnrty_3&lt;BR /&gt;28 mnrty_1&lt;BR /&gt;29 mnrty_4&lt;BR /&gt;30 mnrty_5&lt;BR /&gt;31 mnrty_6;&lt;BR /&gt;32&lt;BR /&gt;33 /* SPECIFY VARIABLE SET FOR THE MCAR TEST */&lt;BR /&gt;34&lt;BR /&gt;35 %let testvars =&lt;BR /&gt;36 GRE&lt;BR /&gt;37 GPA&lt;BR /&gt;38 CSES_Total_Ori&lt;BR /&gt;39 CSES_Total_Prac&lt;BR /&gt;40 CSES_Total_Intern;&lt;BR /&gt;41&lt;BR /&gt;42 /* SPECIFY THE MISSING VALUE CODE */&lt;BR /&gt;43&lt;BR /&gt;44 %let misscode = .;&lt;BR /&gt;45&lt;BR /&gt;46 /*******************************/&lt;BR /&gt;47 /* DO NOT ALTER THE CODE BELOW */&lt;BR /&gt;48 /*******************************/&lt;BR /&gt;49&lt;BR /&gt;50 data one;&lt;BR /&gt;51 infile &amp;amp;datafile ;&lt;BR /&gt;52 input &amp;amp;varlist;&lt;BR /&gt;53&lt;BR /&gt;54 %let numvars = %sysfunc(countw(&amp;amp;testvars));&lt;BR /&gt;55&lt;BR /&gt;56 array m[&amp;amp;numvars] &amp;amp;testvars ;&lt;BR /&gt;57 array r[&amp;amp;numvars] r1 - r&amp;amp;numvars ;&lt;BR /&gt;58&lt;BR /&gt;59 do i = 1 to &amp;amp;numvars;&lt;BR /&gt;60 if m[i] = &amp;amp;misscode then m[i] = .;&lt;BR /&gt;61 end;&lt;BR /&gt;62 drop i;&lt;BR /&gt;63&lt;BR /&gt;64 do i = 1 to &amp;amp;numvars;&lt;BR /&gt;65 r[i] = 1;&lt;BR /&gt;66 if m[i] = . then r[i] = 0;&lt;BR /&gt;67 end;&lt;BR /&gt;68 drop i;&lt;BR /&gt;69&lt;BR /&gt;70 proc sort;&lt;BR /&gt;71 by r1-r&amp;amp;numvars;&lt;BR /&gt;72&lt;BR /&gt;73 proc mi data = one nimpute = 0 noprint;&lt;BR /&gt;74 var &amp;amp;testvars;&lt;BR /&gt;75 em outem = emcov;&lt;BR /&gt;76&lt;BR /&gt;77 proc iml;&lt;BR /&gt;78&lt;BR /&gt;79 use one;&lt;BR /&gt;80 read all var {&amp;amp;testvars} into y;&lt;BR /&gt;81 read all var {%do i = 1 %to &amp;amp;numvars; r&amp;amp;i %end;} into r;&lt;BR /&gt;82 use emcov;&lt;BR /&gt;83 read all var {&amp;amp;testvars} into em;&lt;BR /&gt;84&lt;BR /&gt;85 mu = em[1,];&lt;BR /&gt;86 sigma = em[2:nrow(em),];&lt;BR /&gt;87&lt;BR /&gt;88 /* ASSIGN AN INDEX VARIABLE DENOTING EACH CASE'S PATTERN */&lt;BR /&gt;89&lt;BR /&gt;90 jcol = j(nrow(y), 1 , 1);&lt;BR /&gt;91&lt;BR /&gt;92 do i = 2 to nrow(y);&lt;BR /&gt;93 rdiff = r[i,] - r[i - 1,];&lt;BR /&gt;94 if max(rdiff) = 0 &amp;amp; min(rdiff) = 0 then jcol[i,] = jcol[i - 1,];&lt;BR /&gt;95 else jcol[i,] = jcol[i - 1,] + 1;&lt;BR /&gt;96 end;&lt;BR /&gt;97&lt;BR /&gt;98 /* NUMBER OF DISTINCT MISSING DATA PATTERNS */&lt;BR /&gt;99&lt;BR /&gt;100 j = max(jcol);&lt;BR /&gt;101&lt;BR /&gt;102 /* PUT THE NUMBER OF CASES IN EACH PATTERN IN A COL VECTOR M */&lt;BR /&gt;103 /* PUT THE MISSING DATA INDICATORS FOR EACH PATTERN IN A MATRIX RJ */&lt;BR /&gt;104&lt;BR /&gt;105 m = j(j, 1, 0);&lt;BR /&gt;106 rj = j(j, ncol(r), 0);&lt;BR /&gt;107&lt;BR /&gt;108 do i = 1 to j;&lt;BR /&gt;109 count = 0;&lt;BR /&gt;110 do k = 1 to nrow(y);&lt;BR /&gt;111 if jcol[k,] = i then do;&lt;BR /&gt;112 count = count + 1;&lt;BR /&gt;113 end;&lt;BR /&gt;114 if jcol[k,] = i &amp;amp; count = 1 then rj[i,] = r[k,];&lt;BR /&gt;115 m[i,] = count;&lt;BR /&gt;116 end;&lt;BR /&gt;117 end;&lt;BR /&gt;118&lt;BR /&gt;119 /* COMPUTE D^2 STATISTIC FOR EACH J PATTERN */&lt;BR /&gt;120&lt;BR /&gt;121 d2j = j(j, 1, 0);&lt;BR /&gt;122&lt;BR /&gt;123 do i = 1 to j;&lt;BR /&gt;124&lt;BR /&gt;125 /* OBSERVED VALUES FOR PATTERN J */&lt;BR /&gt;126&lt;BR /&gt;127 yj = y[loc(jcol = i),loc(rj[i,] = 1)];&lt;BR /&gt;128&lt;BR /&gt;129 /* VARIABLE MEANS FOR PATTERN J */&lt;BR /&gt;130&lt;BR /&gt;131 ybarobsj = yj[+,]/nrow(yj);&lt;BR /&gt;132&lt;BR /&gt;133 /* D = P X Pj MATRIX OF INDICATORS (SEE P. 1199) */&lt;BR /&gt;134&lt;BR /&gt;135 Dj = j(ncol(y), rj[i,+], 0);&lt;BR /&gt;136&lt;BR /&gt;137 count = 1;&lt;BR /&gt;138 do k = 1 to ncol(rj);&lt;BR /&gt;139 if rj[i,k] = 1 then do;&lt;BR /&gt;140 Dj[k, count] = 1;&lt;BR /&gt;141 count = count + 1;&lt;BR /&gt;142 end;&lt;BR /&gt;143 end;&lt;BR /&gt;144&lt;BR /&gt;145 /* REDUCE EM ESTIMATES TO CONTAIN OBSERVED ELEMENTS */&lt;BR /&gt;146&lt;BR /&gt;147 muobsj = mu * Dj;&lt;BR /&gt;148 sigmaobsj = t(Dj) * sigma * Dj;&lt;BR /&gt;149&lt;BR /&gt;150 /* THE CONTRIBUTION TO THE D^2 STATISTIC FOR EACH OF THE J PATTERNS */&lt;BR /&gt;151&lt;BR /&gt;152 d2j[i,] = m[i,] * (ybarobsj - muobsj) * inv(sigmaobsj) * t(ybarobsj - muobsj);&lt;BR /&gt;153&lt;BR /&gt;154 end;&lt;BR /&gt;155&lt;BR /&gt;156 /* THE D^2 STATISTIC */&lt;BR /&gt;157&lt;BR /&gt;158 d2 = d2j[+,];&lt;BR /&gt;159&lt;BR /&gt;160 /* DF FOR D^2 */&lt;BR /&gt;161&lt;BR /&gt;162 df = rj[+,+] - ncol(rj);&lt;BR /&gt;163 p = 1 - probchi(d2,df);&lt;BR /&gt;164&lt;BR /&gt;165 /* PRINT ANALYSIS RESULTS */&lt;BR /&gt;166&lt;BR /&gt;167 file print;&lt;BR /&gt;168 put "Number of Observed Variables = " (ncol(rj)) 3.0;&lt;BR /&gt;169 put "Number of Missing Data Patterns = " (j) 3.0; put;&lt;BR /&gt;170 put "Summary of Missing Data Patterns (0 = Missing, 1 = Observed)"; put;&lt;BR /&gt;171 put "Frequency | Pattern | d2j"; put;&lt;BR /&gt;172 do i = 1 to nrow(rj);&lt;BR /&gt;173 put (m[i,]) 6.0 " | " @;&lt;BR /&gt;174 do j = 1 to ncol(rj);&lt;BR /&gt;175 put (rj[i,j]) 2.0 @;&lt;BR /&gt;176 end;&lt;BR /&gt;177 put " | " (d2j[i,]) 8.6;&lt;BR /&gt;178 end;&lt;BR /&gt;179 put;&lt;BR /&gt;180 put "Sum of the Number of Observed Variables Across Patterns (Sigma psubj) = " (rj[+,+]) 5.0;&lt;BR /&gt;180! put;&lt;BR /&gt;181 put "Little's (1988) Chi-Square Test of MCAR"; put;&lt;BR /&gt;182 put "Chi-Square (d2) = " (d2) 10.3;&lt;BR /&gt;183 put "df (Sigma psubj - p) = " (df) 7.0;&lt;BR /&gt;184 put "p-value = " (p) 10.3;&lt;BR /&gt;185&lt;BR /&gt;186 %mend mcartest;&lt;BR /&gt;187 %mcartest;&lt;BR /&gt;NOTE: Line generated by the invoked macro "MCARTEST".&lt;BR /&gt;1 DATA = WORK.Newtwo;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference DATAFILE not resolved.&lt;BR /&gt;NOTE 137-205: Line generated by the invoked macro "MCARTEST".&lt;BR /&gt;3 data one; infile &amp;amp;datafile ; input &amp;amp;varlist;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "MCARTEST".&lt;BR /&gt;3 data one; infile &amp;amp;datafile ; input &amp;amp;varlist;&lt;BR /&gt;-&lt;BR /&gt;200&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference DATAFILE not resolved.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.ONE may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 21 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.25 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Input data set is empty.&lt;BR /&gt;NOTE: The data set WORK.ONE has 0 observations and 21 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.07 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Writing HTML Body file: sashtml.htm&lt;BR /&gt;NOTE: No observations in data set WORK.ONE.&lt;BR /&gt;NOTE: The data set WORK.EMCOV has 0 observations and 7 variables.&lt;BR /&gt;NOTE: PROCEDURE MI used (Total process time):&lt;BR /&gt;real time 0.86 seconds&lt;BR /&gt;cpu time 0.28 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: IML Ready&lt;BR /&gt;WARNING: Data set WORK.ONE is empty.&lt;/P&gt;&lt;P&gt;statement : USE at line 187 column 1&lt;BR /&gt;WARNING: End of File reached.&lt;/P&gt;&lt;P&gt;statement : READ at line 187 column 1&lt;BR /&gt;WARNING: End of File reached.&lt;/P&gt;&lt;P&gt;statement : READ at line 187 column 1&lt;BR /&gt;WARNING: Data set WORK.EMCOV is empty.&lt;/P&gt;&lt;P&gt;statement : USE at line 187 column 1&lt;BR /&gt;WARNING: End of File reached.&lt;/P&gt;&lt;P&gt;statement : READ at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : [ at line 187 column 1&lt;BR /&gt;operands : em, *LIT1004,&lt;/P&gt;&lt;P&gt;em 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*LIT1004 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : [ at line 187 column 1&lt;BR /&gt;operands : em, *LIT1005, _TEM1001,&lt;/P&gt;&lt;P&gt;em 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*LIT1005 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;_TEM1001 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Invalid operand to operation.&lt;/P&gt;&lt;P&gt;operation : J at line 187 column 1&lt;BR /&gt;operands : _TEM1001, *LIT1006, *LIT1007&lt;/P&gt;&lt;P&gt;_TEM1001 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;*LIT1006 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;*LIT1007 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : MAX at line 187 column 1&lt;BR /&gt;operands : jcol&lt;/P&gt;&lt;P&gt;jcol 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : J at line 187 column 1&lt;BR /&gt;operands : j, *LIT1015, *LIT1016&lt;/P&gt;&lt;P&gt;j 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*LIT1015 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;*LIT1016 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : J at line 187 column 1&lt;BR /&gt;operands : j, _TEM1001, *LIT1017&lt;/P&gt;&lt;P&gt;j 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_TEM1001 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;*LIT1017 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: DO expression not given value.&lt;/P&gt;&lt;P&gt;statement : DO at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : J at line 187 column 1&lt;BR /&gt;operands : j, *LIT1023, *LIT1024&lt;/P&gt;&lt;P&gt;j 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*LIT1023 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;*LIT1024 1 row 1 col (numeric)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: DO expression not given value.&lt;/P&gt;&lt;P&gt;statement : DO at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : [ at line 187 column 1&lt;BR /&gt;operands : d2j, $SUB0001,&lt;/P&gt;&lt;P&gt;d2j 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : [ at line 187 column 1&lt;BR /&gt;operands : rj, $SUB0001, $SUB0001&lt;/P&gt;&lt;P&gt;rj 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : PROBCHI at line 187 column 1&lt;BR /&gt;operands : d2, df&lt;/P&gt;&lt;P&gt;d2 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;df 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;statement : ASSIGN at line 187 column 1&lt;BR /&gt;NOTE: Non-portable document will be produced. The current settings of FORMCHAR use nonstandard&lt;BR /&gt;line-drawing characters and the resulting output file will not render correctly unless all&lt;BR /&gt;readers of the document have the SAS Monospace font installed. To make your document&lt;BR /&gt;portable, issue the following command:&lt;BR /&gt;OPTIONS FORMCHAR="|----|+|---+=|-/\&amp;lt;&amp;gt;*";&lt;/P&gt;&lt;P&gt;ERROR: Operand j does not have a value.&lt;/P&gt;&lt;P&gt;statement : PUT at line 187 column 1&lt;BR /&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;operation : [ at line 187 column 1&lt;BR /&gt;operands : rj, $SUB0001, $SUB0001&lt;/P&gt;&lt;P&gt;rj 0 row 0 col (type ?, size 0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;statement : PUT at line 187 column 1&lt;BR /&gt;ERROR: Operand d2 does not have a value.&lt;/P&gt;&lt;P&gt;statement : PUT at line 187 column 1&lt;BR /&gt;ERROR: Operand df does not have a value.&lt;/P&gt;&lt;P&gt;statement : PUT at line 187 column 1&lt;BR /&gt;ERROR: Operand p does not have a value.&lt;/P&gt;&lt;P&gt;statement : PUT at line 187 column 1&lt;BR /&gt;188&lt;BR /&gt;189 run;&lt;BR /&gt;NOTE: Module MAIN is undefined in IML; cannot be RUN.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 01:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414210#M21724</guid>
      <dc:creator>dhahs</dc:creator>
      <dc:date>2017-11-17T01:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414214#M21725</link>
      <description>&lt;P&gt;Where did you get the macro from and can you please include the code you've used and how you called the macro. Yes, its in the log, but harder to read from there. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 02:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414214#M21725</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-17T02:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414258#M21727</link>
      <description>&lt;P&gt;The macro came from here:&amp;nbsp;&amp;nbsp;&lt;A href="http://www.appliedmissingdata.com/macro-programs.html" target="_self"&gt;http://www.appliedmissingdata.com/macro-programs.html&lt;/A&gt;&amp;nbsp;and I've pasted it below.&lt;/P&gt;&lt;P&gt;I've&amp;nbsp; using various syntax for calling in the data as the code in the macro for that, specifically&lt;/P&gt;&lt;PRE&gt;%let datafile = "c:\data\eatingrisk.dat"; &lt;/PRE&gt;&lt;P&gt;created errors.&amp;nbsp; Thank you for your help!&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;/******************************************************************************************************************/&lt;BR /&gt;* *&lt;BR /&gt;* This SAS macro implements the chi-square test for a missing completely at random (MCAR) mechanism, as *&lt;BR /&gt;* outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or higher) because *&lt;BR /&gt;* PROC MI is used to obtain ML estimates of the covariance matrix and mean vector. * *&lt;BR /&gt;* *&lt;BR /&gt;/******************************************************************************************************************/;&lt;/P&gt;&lt;P&gt;%macro mcartest;&lt;/P&gt;&lt;P&gt;/* SPECIFY FILE PATH FOR THE INPUT DATA */&lt;BR /&gt;%let DATA = WORK.Newtwo;&lt;/P&gt;&lt;P&gt;/* SPECIFY INPUT DATA VARIABLE LIST */&lt;/P&gt;&lt;P&gt;%let varlist = Age&lt;BR /&gt;Began&lt;BR /&gt;Track&lt;BR /&gt;BioGender&lt;BR /&gt;Minority&lt;BR /&gt;GRE&lt;BR /&gt;GPA&lt;BR /&gt;CSES_Total_Ori&lt;BR /&gt;CSES_Total_Prac&lt;BR /&gt;CSES_Total_Intern&lt;BR /&gt;mnrty_2&lt;BR /&gt;mnrty_3&lt;BR /&gt;mnrty_1&lt;BR /&gt;mnrty_4&lt;BR /&gt;mnrty_5&lt;BR /&gt;mnrty_6;&lt;/P&gt;&lt;P&gt;/* SPECIFY VARIABLE SET FOR THE MCAR TEST */&lt;/P&gt;&lt;P&gt;%let testvars =&lt;BR /&gt;GRE&lt;BR /&gt;GPA&lt;BR /&gt;CSES_Total_Ori&lt;BR /&gt;CSES_Total_Prac&lt;BR /&gt;CSES_Total_Intern;&lt;/P&gt;&lt;P&gt;/* SPECIFY THE MISSING VALUE CODE */&lt;BR /&gt;&lt;BR /&gt;%let misscode = .;&lt;BR /&gt;&lt;BR /&gt;/*******************************/&lt;BR /&gt;/* DO NOT ALTER THE CODE BELOW */&lt;BR /&gt;/*******************************/&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;infile &amp;amp;datafile ;&lt;BR /&gt;input &amp;amp;varlist;&lt;/P&gt;&lt;P&gt;%let numvars = %sysfunc(countw(&amp;amp;testvars));&lt;/P&gt;&lt;P&gt;array m[&amp;amp;numvars] &amp;amp;testvars ;&lt;BR /&gt;array r[&amp;amp;numvars] r1 - r&amp;amp;numvars ;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;numvars;&lt;BR /&gt;if m[i] = &amp;amp;misscode then m[i] = .;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;numvars;&lt;BR /&gt;r[i] = 1;&lt;BR /&gt;if m[i] = . then r[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt;by r1-r&amp;amp;numvars;&lt;/P&gt;&lt;P&gt;proc mi data = one nimpute = 0 noprint;&lt;BR /&gt;var &amp;amp;testvars;&lt;BR /&gt;em outem = emcov;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;use one;&lt;BR /&gt;read all var {&amp;amp;testvars} into y;&lt;BR /&gt;read all var {%do i = 1 %to &amp;amp;numvars; r&amp;amp;i %end;} into r;&lt;BR /&gt;use emcov;&lt;BR /&gt;read all var {&amp;amp;testvars} into em;&lt;/P&gt;&lt;P&gt;mu = em[1,];&lt;BR /&gt;sigma = em[2:nrow(em),];&lt;/P&gt;&lt;P&gt;/* ASSIGN AN INDEX VARIABLE DENOTING EACH CASE'S PATTERN */&lt;/P&gt;&lt;P&gt;jcol = j(nrow(y), 1 , 1);&lt;/P&gt;&lt;P&gt;do i = 2 to nrow(y);&lt;BR /&gt;rdiff = r[i,] - r[i - 1,];&lt;BR /&gt;if max(rdiff) = 0 &amp;amp; min(rdiff) = 0 then jcol[i,] = jcol[i - 1,];&lt;BR /&gt;else jcol[i,] = jcol[i - 1,] + 1;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* NUMBER OF DISTINCT MISSING DATA PATTERNS */&lt;/P&gt;&lt;P&gt;j = max(jcol);&lt;/P&gt;&lt;P&gt;/* PUT THE NUMBER OF CASES IN EACH PATTERN IN A COL VECTOR M */&lt;BR /&gt;/* PUT THE MISSING DATA INDICATORS FOR EACH PATTERN IN A MATRIX RJ */&lt;/P&gt;&lt;P&gt;m = j(j, 1, 0);&lt;BR /&gt;rj = j(j, ncol(r), 0);&lt;/P&gt;&lt;P&gt;do i = 1 to j;&lt;BR /&gt;count = 0;&lt;BR /&gt;do k = 1 to nrow(y);&lt;BR /&gt;if jcol[k,] = i then do;&lt;BR /&gt;count = count + 1;&lt;BR /&gt;end;&lt;BR /&gt;if jcol[k,] = i &amp;amp; count = 1 then rj[i,] = r[k,];&lt;BR /&gt;m[i,] = count;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* COMPUTE D^2 STATISTIC FOR EACH J PATTERN */&lt;/P&gt;&lt;P&gt;d2j = j(j, 1, 0);&lt;/P&gt;&lt;P&gt;do i = 1 to j;&lt;/P&gt;&lt;P&gt;/* OBSERVED VALUES FOR PATTERN J */&lt;/P&gt;&lt;P&gt;yj = y[loc(jcol = i),loc(rj[i,] = 1)];&lt;/P&gt;&lt;P&gt;/* VARIABLE MEANS FOR PATTERN J */&lt;/P&gt;&lt;P&gt;ybarobsj = yj[+,]/nrow(yj);&lt;/P&gt;&lt;P&gt;/* D = P X Pj MATRIX OF INDICATORS (SEE P. 1199) */&lt;/P&gt;&lt;P&gt;Dj = j(ncol(y), rj[i,+], 0);&lt;/P&gt;&lt;P&gt;count = 1;&lt;BR /&gt;do k = 1 to ncol(rj);&lt;BR /&gt;if rj[i,k] = 1 then do;&lt;BR /&gt;Dj[k, count] = 1;&lt;BR /&gt;count = count + 1;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/* REDUCE EM ESTIMATES TO CONTAIN OBSERVED ELEMENTS */&lt;/P&gt;&lt;P&gt;muobsj = mu * Dj;&lt;BR /&gt;sigmaobsj = t(Dj) * sigma * Dj;&lt;/P&gt;&lt;P&gt;/* THE CONTRIBUTION TO THE D^2 STATISTIC FOR EACH OF THE J PATTERNS */&lt;/P&gt;&lt;P&gt;d2j[i,] = m[i,] * (ybarobsj - muobsj) * inv(sigmaobsj) * t(ybarobsj - muobsj);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;/* THE D^2 STATISTIC */&lt;/P&gt;&lt;P&gt;d2 = d2j[+,];&lt;/P&gt;&lt;P&gt;/* DF FOR D^2 */&lt;/P&gt;&lt;P&gt;df = rj[+,+] - ncol(rj);&lt;BR /&gt;p = 1 - probchi(d2,df);&lt;/P&gt;&lt;P&gt;/* PRINT ANALYSIS RESULTS */&lt;/P&gt;&lt;P&gt;file print;&lt;BR /&gt;put "Number of Observed Variables = " (ncol(rj)) 3.0;&lt;BR /&gt;put "Number of Missing Data Patterns = " (j) 3.0; put;&lt;BR /&gt;put "Summary of Missing Data Patterns (0 = Missing, 1 = Observed)"; put;&lt;BR /&gt;put "Frequency | Pattern | d2j"; put;&lt;BR /&gt;do i = 1 to nrow(rj);&lt;BR /&gt;put (m[i,]) 6.0 " | " @;&lt;BR /&gt;do j = 1 to ncol(rj);&lt;BR /&gt;put (rj[i,j]) 2.0 @;&lt;BR /&gt;end;&lt;BR /&gt;put " | " (d2j[i,]) 8.6;&lt;BR /&gt;end;&lt;BR /&gt;put;&lt;BR /&gt;put "Sum of the Number of Observed Variables Across Patterns (Sigma psubj) = " (rj[+,+]) 5.0; put;&lt;BR /&gt;put "Little's (1988) Chi-Square Test of MCAR"; put;&lt;BR /&gt;put "Chi-Square (d2) = " (d2) 10.3;&lt;BR /&gt;put "df (Sigma psubj - p) = " (df) 7.0;&lt;BR /&gt;put "p-value = " (p) 10.3;&lt;/P&gt;&lt;P&gt;%mend mcartest;&lt;BR /&gt;%mcartest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 05:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/414258#M21727</guid>
      <dc:creator>dhahs</dc:creator>
      <dc:date>2017-11-17T05:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Little's MCAR Macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/421108#M22155</link>
      <description>&lt;P&gt;i'm in the same case, please let me know if you succeeded.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 08:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Little-s-MCAR-Macro/m-p/421108#M22155</guid>
      <dc:creator>sarah4</dc:creator>
      <dc:date>2017-12-14T08:39:36Z</dc:date>
    </item>
  </channel>
</rss>

