<?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: Issue with Little's MCAR macro in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-with-Little-s-MCAR-macro/m-p/575170#M4753</link>
    <description>you need to also show how you're calling the macro and the log. It's possible the issue is with your data.</description>
    <pubDate>Sat, 20 Jul 2019 23:04:45 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-20T23:04:45Z</dc:date>
    <item>
      <title>Issue with Little's MCAR macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-with-Little-s-MCAR-macro/m-p/575166#M4752</link>
      <description>&lt;P&gt;I am not a proficient macro user and have not used PROC IML prior to now, so forgive me if the answer is obvious.&amp;nbsp; I'm working with SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the code, the only error I receive is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"ERROR: (execution) Matrix has not been set to a value."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am familiar with the fact that this error generally means that something has not been defined (ex. y=x, but x doesn't exist).&amp;nbsp; I have scoured the previous boards, and read through SAS documents, and have not been able to identify why the final %mcartest (line 4329) would result in this error.&amp;nbsp; Previous problems, using the same macro, were related to data input and perhaps errors within the code, but I have not come across any examples where the source of error is the %mcartest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone can provide some feedback/suggestions, I would greatly appreciate it.&amp;nbsp; I have attached the original code as a word document and the log (with error statement) as a PDF for convenience, as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**********************************************************************************************************************************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro mcartest&lt;BR /&gt;(indata= ems.recodeptsd /* Input DATASET name */&lt;BR /&gt;,testvars= sc1 ptsd1_1 ptsd1_2 ptsd1_3 ptsd1_4 ptsd1_5 ptsd1_6 ptsd1_7 ptsd1_8 ptsd1_9 ptsd1_10 ptsd1_11 ptsd1_12 ptsd1_13&lt;BR /&gt;ptsd1_14 ptsd1_15 ptsd1_16 ptsd1_17 /* SPECIFY VARIABLE SET FOR THE MCAR TEST */&lt;BR /&gt;,misscode= . /* SPECIFY THE MISSING VALUE CODE */&lt;BR /&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;/P&gt;&lt;P&gt;%local numvars ;&lt;BR /&gt;%let numvars = %sysfunc(countw(&amp;amp;testvars));&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;set &amp;amp;indata (keep=&amp;amp;testvars);&lt;BR /&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;r[i] = not missing(m[i]);&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt;by r1-r&amp;amp;numvars;&lt;BR /&gt;run;&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;BR /&gt;run;&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;BR /&gt;yj = y[loc(jcol = i),loc(rj[i,] = 1)];&lt;/P&gt;&lt;P&gt;/* VARIABLE MEANS FOR PATTERN J */&lt;BR /&gt;ybarobsj = yj[+,]/nrow(yj);&lt;/P&gt;&lt;P&gt;/* D = P X Pj MATRIX OF INDICATORS (SEE P. 1199) */&lt;BR /&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;BR /&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;BR /&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;BR /&gt;d2 = d2j[+,];&lt;/P&gt;&lt;P&gt;/* DF FOR D^2 */&lt;BR /&gt;df = rj[+,+] - ncol(rj);&lt;BR /&gt;p = 1 - probchi(d2,df);&lt;/P&gt;&lt;P&gt;/* PRINT ANALYSIS RESULTS */&lt;BR /&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;/P&gt;&lt;P&gt;%mcartest&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2019 20:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-with-Little-s-MCAR-macro/m-p/575166#M4752</guid>
      <dc:creator>Arbormazoo</dc:creator>
      <dc:date>2019-07-20T20:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Little's MCAR macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-with-Little-s-MCAR-macro/m-p/575170#M4753</link>
      <description>you need to also show how you're calling the macro and the log. It's possible the issue is with your data.</description>
      <pubDate>Sat, 20 Jul 2019 23:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-with-Little-s-MCAR-macro/m-p/575170#M4753</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-20T23:04:45Z</dc:date>
    </item>
  </channel>
</rss>

