Little's MCAR macro

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Little's MCAR macro

Hello, 

 

I am new to SAS and this is my first time running a macro. I want to run Little's test to determine if missingness is completely at random. The macro is available here http://www.appliedmissingdata.com/littles-mcar-test.sas 

I am having trouble reading in my datafile. My data file is already a sas file (.sas7bdat) so the macro is not getting that. However, I need to keep the "datafile" because it is something the macro uses later on. I tried saving my file using different extensions (.txt for example) and read it in using the datafile statement but again got error messages (invalid data for VAR name). I looked online and several suggestions included adding dlm=',' or dlm='09'x did not work. Eventually the macro ran with a .dat file and the dlm option added to the datafile statement (%let datafile = "C:\Users\eltoukhysm\Desktop\macro.dat" dlm=','; )
but the results are inconsistent with the ones I got from running the same test in SPSS. Also I ran proc mi to identify patterns of missing data, and that is inconsistent with the results the macro is giving me as well. 

Any advice is much appreciated.  

 

 

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

%let datafile = "c:\data\eatingrisk.dat";

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = abuse bmi bds1 bds2 bds3 bds4 bds5 bds6 bds7 edr1 edr2 edr3 edr4 edr5 edr6;

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = abuse bds1 bds2 bds3 bds4 bds5 bds6 bds7;

/* SPECIFY THE MISSING VALUE CODE */

%let misscode = -99;


Accepted Solutions
Solution
‎06-08-2018 12:47 PM
Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy

The macro is designed to wrok off a text file and you don't have a text file. YOu have two options as I see it:

 

1. Modify the code to use a SAS data set - relatively easy. 

2. Export your SAS data set to a text file and then use the macro as designed.

 

data one;
infile &datafile ;
input &varlist;

Try replacing these lines with:

 

libname myData 'path to my sas7bdat folder';


data one;
set myData.eatingRisk;

.....

rest of the code

....

Where myData is your library. 

If you have changed the extension you may need to get a new file as it may be corrupt now. 

 


@sherineeltoukhy wrote:

I assigned the library - the macro did not run, gave me all sorts of error. I am posting the complete macro below and as you can see it needs the datafile statement later on. 

 

/******************************************************************************************************************/
* *
* This SAS macro implements the chi-square test for a missing completely at random (MCAR) mechanism, as *
* outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or higher) because *
* PROC MI is used to obtain ML estimates of the covariance matrix and mean vector. * *
* *
/******************************************************************************************************************/;

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

%let datafile = "c:\data\eatingrisk.dat";

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = abuse bmi bds1 bds2 bds3 bds4 bds5 bds6 bds7 edr1 edr2 edr3 edr4 edr5 edr6;

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = abuse bds1 bds2 bds3 bds4 bds5 bds6 bds7;

/* SPECIFY THE MISSING VALUE CODE */

%let misscode = -99;

/*******************************/
/* DO NOT ALTER THE CODE BELOW */
/*******************************/

data one;
infile &datafile ;
input &varlist;

%let numvars = %sysfunc(countw(&testvars));

array m[&numvars] &testvars ;
array r[&numvars] r1 - r&numvars ;

do i = 1 to &numvars;
if m[i] = &misscode then m[i] = .;
end;
drop i;

do i = 1 to &numvars;
r[i] = 1;
if m[i] = . then r[i] = 0;
end;
drop i;

proc sort;
by r1-r&numvars;

proc mi data = one nimpute = 0 noprint;
var &testvars;
em outem = emcov;

proc iml;

use one;
read all var {&testvars} into y;
read all var {%do i = 1 %to &numvars; r&i %end;} into r;
use emcov;
read all var {&testvars} 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 & 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;
if jcol[k,] = i & 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;

/* 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;


 

View solution in original post


All Replies
Valued Guide
Posts: 590

Re: Little's MCAR macro

[ Edited ]
Posted in reply to sherineeltoukhy

Your are trying to read the sas dataset in the wrong way. If you have saved the sas dataset (test.sas7bdat) in "c:\data\" location then you can directly read the dataset by assigning the libname.

 

LIBNAME mydate "c:\data\";

 

proc print data=mydata.test;

run;

Thanks,
Suryakiran
Occasional Contributor
Posts: 12

Re: Little's MCAR macro

Posted in reply to SuryaKiran

I assigned the library - the macro did not run, gave me all sorts of error. I am posting the complete macro below and as you can see it needs the datafile statement later on. 

 

/******************************************************************************************************************/
* *
* This SAS macro implements the chi-square test for a missing completely at random (MCAR) mechanism, as *
* outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or higher) because *
* PROC MI is used to obtain ML estimates of the covariance matrix and mean vector. * *
* *
/******************************************************************************************************************/;

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

%let datafile = "c:\data\eatingrisk.dat";

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = abuse bmi bds1 bds2 bds3 bds4 bds5 bds6 bds7 edr1 edr2 edr3 edr4 edr5 edr6;

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = abuse bds1 bds2 bds3 bds4 bds5 bds6 bds7;

/* SPECIFY THE MISSING VALUE CODE */

%let misscode = -99;

/*******************************/
/* DO NOT ALTER THE CODE BELOW */
/*******************************/

data one;
infile &datafile ;
input &varlist;

%let numvars = %sysfunc(countw(&testvars));

array m[&numvars] &testvars ;
array r[&numvars] r1 - r&numvars ;

do i = 1 to &numvars;
if m[i] = &misscode then m[i] = .;
end;
drop i;

do i = 1 to &numvars;
r[i] = 1;
if m[i] = . then r[i] = 0;
end;
drop i;

proc sort;
by r1-r&numvars;

proc mi data = one nimpute = 0 noprint;
var &testvars;
em outem = emcov;

proc iml;

use one;
read all var {&testvars} into y;
read all var {%do i = 1 %to &numvars; r&i %end;} into r;
use emcov;
read all var {&testvars} 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 & 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;
if jcol[k,] = i & 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;

/* 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;

Solution
‎06-08-2018 12:47 PM
Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy

The macro is designed to wrok off a text file and you don't have a text file. YOu have two options as I see it:

 

1. Modify the code to use a SAS data set - relatively easy. 

2. Export your SAS data set to a text file and then use the macro as designed.

 

data one;
infile &datafile ;
input &varlist;

Try replacing these lines with:

 

libname myData 'path to my sas7bdat folder';


data one;
set myData.eatingRisk;

.....

rest of the code

....

Where myData is your library. 

If you have changed the extension you may need to get a new file as it may be corrupt now. 

 


@sherineeltoukhy wrote:

I assigned the library - the macro did not run, gave me all sorts of error. I am posting the complete macro below and as you can see it needs the datafile statement later on. 

 

/******************************************************************************************************************/
* *
* This SAS macro implements the chi-square test for a missing completely at random (MCAR) mechanism, as *
* outlined in Little's (1998) JASA article. Note that the macro requires SAS version 8.2 (or higher) because *
* PROC MI is used to obtain ML estimates of the covariance matrix and mean vector. * *
* *
/******************************************************************************************************************/;

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

%let datafile = "c:\data\eatingrisk.dat";

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = abuse bmi bds1 bds2 bds3 bds4 bds5 bds6 bds7 edr1 edr2 edr3 edr4 edr5 edr6;

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = abuse bds1 bds2 bds3 bds4 bds5 bds6 bds7;

/* SPECIFY THE MISSING VALUE CODE */

%let misscode = -99;

/*******************************/
/* DO NOT ALTER THE CODE BELOW */
/*******************************/

data one;
infile &datafile ;
input &varlist;

%let numvars = %sysfunc(countw(&testvars));

array m[&numvars] &testvars ;
array r[&numvars] r1 - r&numvars ;

do i = 1 to &numvars;
if m[i] = &misscode then m[i] = .;
end;
drop i;

do i = 1 to &numvars;
r[i] = 1;
if m[i] = . then r[i] = 0;
end;
drop i;

proc sort;
by r1-r&numvars;

proc mi data = one nimpute = 0 noprint;
var &testvars;
em outem = emcov;

proc iml;

use one;
read all var {&testvars} into y;
read all var {%do i = 1 %to &numvars; r&i %end;} into r;
use emcov;
read all var {&testvars} 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 & 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;
if jcol[k,] = i & 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;

/* 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;


 

Super User
Posts: 13,523

Re: Little's MCAR macro


@Reeza wrote:

The macro is designed to wrok off a text file and you don't have a text file. YOu have two options as I see it:

 

1. Modify the code to use a SAS data set - relatively easy. 

2. Export your SAS data set to a text file and then use the macro as designed.

 


@sherineeltoukhy

 

And take this example as a "how not to write a macro". Generally it is a good idea to separate data reading/import and the analysis steps. Then you don't get things like having a perfectly good workable data set that you have to export and reimport just for one macro to run.

Occasional Contributor
Posts: 12

Re: Little's MCAR macro

[ Edited ]

Thank you for your response. Everyone says it is relatively easy to modify the macro but not for me. I am new to this. I tried replacing the lines of the macro as suggested by @Reeza but it did not work. When I saved my data as a text and ran the macro, it always says that the work file is empty, invalid data for each variable in the dataset, increase buffer. So, it is basically reading the variables but not the observations. Which got me to go down a rabbit hole about infile, datalines, and other fixes suggested by expert users on online support groups, none of which have worked by the way. I still get the error about empty dataset, invalid data for each variable. At the end of the day, I get the print out of what the macro should give me with 0 in front of every line.

 

 

Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy
Post the code with the modifications I suggested and your full log.
Occasional Contributor
Posts: 12

Re: Little's MCAR macro

Here is the modified macro (please note that the dataset has 600+ variables, which I have added to (%let varlist =)  as per the instructions of the macro). After the code is the log.

 

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

Libname hints 'H:\Hints\RM\EHR Manuscript';

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = AccessedFamRec_MyPwd AccessedFamRec_TheirPwd AccessFamilyMedRec AccessOnlineRecord ActiveDutyArmedForces AdultsInHH Age Age_3cat_r Age_3cat_wm Age_I Age_IFlag
AgeDX AgeGrpA AgeGrpB AlcoholConditions_Cancer AlcoholConditions_Cholesterol AlcoholConditions_Diabetes AlcoholConditions_HeartDisease AlcoholConditions_LiverDisease
AlcoholConditions_Overweight AlcoholIncreaseCancer AlcoholReduceHeart AmerInd AnyDevice_r AnyDevice_wm AnyIntAccess_r AnyIntAccess_wm APP_REGION AsInd Black BMI
BornInUSA BornInUSA_r BornInUSA_wm Broadbnd_cc Broadbnd_cc1 Broadbnd_r Broadbnd_wm CaBladder CaBone CaBreast CaCervical CaColon CaEndometrial CaHeadNeck CaHodgkins CaLeukemia
CaLiver CaLung CaMelanoma Cancer_Cat Cancer_IFlag CancerAbilityToWork CancerDeniedCoverage CancerFatal CancerHurtFinances CancerMoreCommon CancerTx_Chemo CancerTx_Other
CancerTx_Radiation CancerTx_Surgery CancerTxSummary CaNonHodgkin CaOral CaOther CaOther_OS CaOvarian CaPancreatic CaPharyngeal CaProstate CaRectal Caregiving_AcuteCond
Caregiving_Aging Caregiving_Alzheimers Caregiving_Cancer Caregiving_Child Caregiving_ChronicCond Caregiving_Family Caregiving_Friend Caregiving_HoursPerWeek Caregiving_MentalHealth
Caregiving_NeuroDev Caregiving_No Caregiving_NotSure Caregiving_OrthoMusc Caregiving_Other Caregiving_Other_OS Caregiving_Parent Caregiving_Spouse CaregivingCond_Cat
CaregivingWho_Cat CaRenal CaSkin CaStomach Cell_cc Cell_cc1 Cell_r Cell_wm cellph_r cellph_wm CellPhone CENSDIV CENSREG ChanceAskQuestions ChanceGetCancer ChildrenInHH Chinese
ClinicalTrialCancerTx ConcernedQuality ConfidentGetHealthInf ConfidentInfoSafe ConsiderQuit Cuban Deaf DeviceCount Dialup_cc Dialup_cc1 Dialup_r Dialup_wm Disabled
DiscussedClinicalTrial DiscussHPVVaccination12m DMA DrTalkLungTest eCigUse EducA Education Education_4cat_r Education_4cat_wm Education_I Education_IFlag EducB
ElectCigLessHarm ElectInfoSafe Electronic_BuyMedicine Electronic_CompletedForms Electronic_HCPSearch Electronic_HealthInfoSE Electronic_MadeAppts Electronic_SelfHealthInfo
Electronic_TalkDoctor Electronic_TestResults Electronic_TrackedHealthCosts EmotionalSupport Employed EMR_Addinfo_cc EMR_Addinfo_cc1 EMR_Addinfo_r EMR_Addinfo_wm EMR_Allergies_cc
EMR_Allergies_cc1 EMR_Allergies_r EMR_Allergies_wm EMR_Appt_cc EMR_Appt_cc1 EMR_Appt_r EMR_Appt_wm EMR_ClinNotes_cc EMR_ClinNotes_cc1 EMR_ClinNotes_r EMR_ClinNotes_wm EMR_Correction_cc
EMR_Correction_cc1 EMR_Correction_r EMR_Correction_wm EMR_DownloadHealth_cc EMR_DownloadHealth_cc1 EMR_DownloadHealth_r EMR_DownloadHealth_wm EMR_HealthProbs_cc EMR_HealthProbs_cc1
EMR_HealthProbs_r EMR_HealthProbs_wm EMR_Immunizations_cc EMR_Immunizations_cc1 EMR_Immunizations_r EMR_Immunizations_wm EMR_labs_cc EMR_labs_cc1 EMR_labs_r EMR_labs_wm EMR_MakeDecision_cc
EMR_MakeDecision_cc1 EMR_MakeDecision_r EMR_MakeDecision_wm EMR_Meds_cc EMR_Meds_cc1 EMR_Meds_r EMR_Meds_wm EMR_MessageHCP_cc EMR_MessageHCP_cc1 EMR_MessageHCP_r EMR_MessageHCP_wm
EMR_MonitorHealth_cc EMR_MonitorHealth_cc1 EMR_MonitorHealth_r EMR_MonitorHealth_wm EMR_paperwork_cc EMR_paperwork_cc1 EMR_paperwork_r EMR_paperwork_wm EMR_RefillMeds_cc
EMR_RefillMeds_cc1 EMR_RefillMeds_r EMR_RefillMeds_wm EMR_Results_cc EMR_Results_cc1 EMR_Results_r EMR_Results_wm EMR_VisitSummary_cc EMR_VisitSummary_cc1 EMR_VisitSummary_r
EMR_VisitSummary_wm EMRprivate_r EMRprivate_wm EMRsafe_r EMRsafe_wm ESent_AnotherHCP ESent_Family ESent_HealthApp EverHadCancer EverHadCancer_I EverHadPSATest EverythingCauseCancer
ExplainedClearly FamBetween9and27 FamilyAccess_r FamilyAccess_wm FamilyEverHadCancer FeelingsAddressed female_r female_wm Filipino FIPS FIPST FormType FreqGoProvider FreqWorryCancer
Fruit Frustrated Gender_IFlag GenderC GenderC_I GeneralHealth GeneticTestUse_Cat GeneticTestUse_DetermineMed GeneticTestUse_DeterminePass GeneticTestUse_DetermineRisk
GeneticTestUse_DetermineTx GenHealth_r GenHealth_wm Guamanian HadTest_Ancestry HadTest_BRCA HadTest_Cat HadTest_CFCarrier HadTest_DNAFing HadTest_Lynch HadTest_None
HadTest_NotSure HadTest_Other HadTest_Other_OS HadTest_Paternity HaveDevice_CellPh HaveDevice_SmartPh HaveDevice_Tablet Hawaiian HCPaccess_r HCPaccess_wm HCPencourage_r HCPencourage_wm
HCPEncourageOnlineRec HealthIns_IHS HealthIns_InsuranceEmp HealthIns_InsurancePriv HealthIns_Medicaid HealthIns_Medicare HealthIns_Other HealthIns_Other_OS HealthIns_Tricare
HealthIns_VA HealthInsurance HealthInsurance_I HealthInsurance_IFlag HealthInsurance_r HealthInsurance_wm HeardDNATest HeardHPV HeardHPVVaccine2 Height_Feet Height_Inches HelpDailyChores
HelpUncertainty HHAdultAge2 HHAdultAge3 HHAdultAge4 HHAdultAge5 HHAdultGender2 HHAdultGender3 HHAdultGender4 HHAdultGender5 HHAdultMOB2 HHAdultMOB3 HHAdultMOB4 HHAdultMOB5 HHAdults_Num
HHID HHInc HIGHSPANLI Hisp_Cat Hisp_Cat_I HISP_HH Hisp_IFlag HISPSURNAME Homemaker HookahLessHarm Hopeless HowLongFinishTreatment_Cat HowLongModerateExerciseHr HowLongModerateExerciseMn
HPVCauseCancer_Anal HPVCauseCancer_Cervical HPVCauseCancer_Oral HPVCauseCancer_Penile HPVMedicalTreatment HPVShotPrevent HPVSTD Income_4cat_r Income_4cat_wm IncomeRanges IncomeRanges_IMP
InsurerAccess_r InsurerAccess_wm IntCount Internet_BroadBnd Internet_Cell Internet_DialUp Internet_WiFi InternetCancerInfoSelf IntRsn_SharedSocNet IntRsn_SupportGroup
IntRsn_VisitedSocNet IntRsn_WroteBlog IntRsn_YouTube InvolvedDecisions Japanese Korean Language_Flag LittleInterest LotOfEffort MailHHAdults MailSurveyTime_Hrs MailSurveyTime_Min
MaintainEMR_r MaintainEMR_wm Marital_IFlag MaritalStatus MaritalStatus_3cat_r MaritalStatus_3cat_wm MaritalStatus_I MedConditions_Arthritis MedConditions_Depression MedConditions_Diabetes
MedConditions_HeartCondition MedConditions_HighBP MedConditions_LungDisease Mexican MostRecentCheckup2 MultiOcc NCHSURCODE2013 Nervous NotAccessed_ConcernedPrivacy NotAccessed_NoInternet
NotAccessed_NoNeed NotAccessed_NoRecord NotAccessed_Other NotAccessed_Other_OS NotAccessed_SpeakDirectly NotHisp occupation_2cat_r occupation_2cat_wm OccupationStatus OccupationStatus_OS
OfferedAccessHCP2 OfferedAccessInsurer2 OthAsian OtherDevTrackHealth OtherOcc OthHisp OthPacIsl OwnAbilityTakeCareHealth OwnAccess_r OwnAccess_wm Ownership_r Ownership_wm PERSON_FINWT0
PERSON_FINWT1 PERSON_FINWT2 PERSON_FINWT3 PERSON_FINWT4 PERSON_FINWT5 PERSON_FINWT6 PERSON_FINWT7 PERSON_FINWT8 PERSON_FINWT9 PERSON_FINWT10 PERSON_FINWT11 PERSON_FINWT12 PERSON_FINWT13
PERSON_FINWT14 PERSON_FINWT15 PERSON_FINWT16 PERSON_FINWT17 PERSON_FINWT18 PERSON_FINWT19 PERSON_FINWT20 PERSON_FINWT21 PERSON_FINWT22 PERSON_FINWT23 PERSON_FINWT24 PERSON_FINWT25
PERSON_FINWT26 PERSON_FINWT27 PERSON_FINWT28 PERSON_FINWT29 PERSON_FINWT30 PERSON_FINWT31 PERSON_FINWT32 PERSON_FINWT33 PERSON_FINWT34 PERSON_FINWT35 PERSON_FINWT36 PERSON_FINWT37
PERSON_FINWT38 PERSON_FINWT39 PERSON_FINWT40 PERSON_FINWT41 PERSON_FINWT42 PERSON_FINWT43 PERSON_FINWT44 PERSON_FINWT45 PERSON_FINWT46 PERSON_FINWT47 PERSON_FINWT48 PERSON_FINWT49
PERSON_FINWT50 PersonID PhoneInHome PHQ4 PR_RUCA_2010 PreventNotPossible ProbCare_BringTest ProbCare_ProvideHist ProbCare_RedoTest ProbCare_WaitLong ProviderMaintainEMR2
PuertoRican QDisp QualityCare R_HHAdults Race_4cat_r Race_4cat_wm Race_Cat2 Race_Cat2_I Race_IFlag RaceEthn RaceEthn5 RatherNotKnowChance ReceivedCareVA RecommendHPVShot
RecordsOnline_AddHealthInfo RecordsOnline_Allergies RecordsOnline_ClinNotes RecordsOnline_DownloadHealth RecordsOnline_HealthProbs RecordsOnline_Immunizations RecordsOnline_Labs
RecordsOnline_MakeAppt RecordsOnline_MakeDecision RecordsOnline_Meds RecordsOnline_MessageHCP RecordsOnline_MonitorHealth RecordsOnline_Paperwork RecordsOnline_RefillMeds
RecordsOnline_RequestCorrection RecordsOnline_ViewResults RecordsOnline_VisitSummary RegularProvider RegularProvider_r RegularProvider_wm RentOrOwn Retired RUC2003 RUC2013
RUC2013_3cat Samoan SEC_RUCA_2010 SeekCancerInfo SeekHealthInfo SelfAge SelfGender SelfMOB SexualOrientation SexualOrientation_I SexualOrientation_IFlag SexualOrientation_OS
SharedHealthDeviceInfo SkinCancerHPExam SkinCancerSelfCheck smartph_r smartph_wm Smoke100 SmokelessLessHarm SmokeNow smokeStat Speak_r Speak_wm SpeakEnglish SpentEnoughTime
Stratum StrongNeedHealthInfo StrongNeedHealthInfo_IFlag StrongNeedHealthInfo_IMP StrongNeedHealthInfo_OS Student Tablet_AchieveGoal Tablet_DiscussionsHCP Tablet_MakeDecision
tablet_r tablet_wm TabletHealthWellnessApps TalkHealthFriends TanningBed TextFromDoctor TimeSinceDX TimesModerateExercise TimesStrengthTraining TooHardUnderstand
TooManyRecommendations TotalHousehold TriedQuit TrustCharities TrustDoctor TrustFamily TrustGov TrustInternet TrustNewsMag TrustRadio TrustReligiousOrgs
TrustTelevision TypeOfAddressA TypeOfAddressB TypeOfAddressC TypeOfAddressD UndergoCancerTreatment UnderstandEMR_cc UnderstandEMR_cc1 UnderstandEMR_r UnderstandEMR_wm
UnderstandOnlineMedRec UnderstoodNextSteps Unemployed UpdateDate UsedECigEver UseECigNow UsefulEMR_cc UsefulEMR_cc1 UsefulEMR_r UsefulEMR_wm UsefulOnlineMedRec
UseInternet UseInternet_r UseInternet_wm UseMenuCalorieInfo Vegetables Vietnamese WeeklyMinutesModerateExercise Weight WhenDiagnosedCancer WhenMammogram WhenPapTest
WhereSeekHealthInfo WhereSeekHealthInfo_IFlag WhereSeekHealthInfo_IMP WhereUseInternet_GamingDevice WhereUseInternet_Home WhereUseInternet_MobileDevice
WhereUseInternet_PublicPlace WhereUseInternet_School WhereUseInternet_Work White WhoLookingFor wifi_cc wifi_cc1 wifi_r wifi_wm WithheldInfoPrivacy Worrying YearCameToUSA ZIP ZIP4;

 

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = female_wm age_3cat_wm race_4cat_wm income_4cat_wm education_4cat_wm occupation_2cat_wm MaritalStatus_3cat_wm BornInUSA_wm speak_wm HealthInsurance_wm RegularProvider_wm
ownership_wm censreg RUC2013_3cat UseInternet_wm Dialup_wm Broadbnd_wm cell_wm wifi_wm tablet_wm smartph_wm cellph_wm GenHealth_wm MaintainEMR_wm HCPaccess_wm
HCPencourage_wm OwnAccess_wm FamilyAccess_wm EMRsafe_wm EMR_Appt_wm EMR_RefillMeds_wm EMR_paperwork_wm EMR_correction_wm EMR_MessageHCP_wm
EMR_results_wm EMR_MonitorHealth_wm EMR_DownloadHealth_wm EMR_Addinfo_wm EMR_MakeDecision_wm EMR_labs_wm EMR_meds_wm EMR_HealthProbs_wm EMR_allergies_wm EMR_VisitSummary_wm
EMR_ClinNotes_wm EMR_Immunizations_wm;

/* SPECIFY THE MISSING VALUE CODE */

%let misscode = .;

/*******************************/
/* DO NOT ALTER THE CODE BELOW */
/*******************************/

Libname hints 'H:\Hints\RM\EHR Manuscript';

data one;
set hints.hints5_cycle1_internal;
input &varlist;

%let numvars = %sysfunc(countw(&testvars));

array m[&numvars] &testvars ;
array r[&numvars] r1 - r&numvars ;

do i = 1 to &numvars;
if m[i] = &misscode then m[i] = .;
end;
drop i;

do i = 1 to &numvars;
r[i] = 1;
if m[i] = . then r[i] = 0;
end;
drop i;

proc sort;
by r1-r&numvars;

proc mi data = one nimpute = 0 noprint;
var &testvars;
em outem = emcov;

proc iml;

use one;
read all var {&testvars} into y;
read all var {%do i = 1 %to &numvars; r&i %end;} into r;
use emcov;
read all var {&testvars} 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 & 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;
if jcol[k,] = i & 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;

/* 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;

 

_________________________Log______________________________

 

NOTE: Libref HINTS was successfully assigned as follows:
Engine: V9
Physical Name: H:\Hints\RM\EHR Manuscript

ERROR: No DATALINES or INFILE statement.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ONE may be incomplete. When this step was stopped there were 0
observations and 647 variables.
NOTE: DATA statement used (Total process time):
real time 0.49 seconds
cpu time 0.06 seconds

 

NOTE: Input data set is empty.
NOTE: The data set WORK.ONE has 0 observations and 647 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds


NOTE: Writing HTML Body file: sashtml.htm
NOTE: No observations in data set WORK.ONE.
NOTE: The data set WORK.EMCOV has 0 observations and 48 variables.
NOTE: PROCEDURE MI used (Total process time):
real time 0.62 seconds
cpu time 0.34 seconds


NOTE: IML Ready
WARNING: Data set WORK.ONE is empty.

statement : USE at line 222 column 1
WARNING: End of File reached.

statement : READ at line 222 column 1
WARNING: End of File reached.

statement : READ at line 222 column 1
WARNING: Data set WORK.EMCOV is empty.

statement : USE at line 222 column 1
WARNING: End of File reached.

statement : READ at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 222 column 1
operands : em, *LIT1004,

em 0 row 0 col (type ?, size 0)


*LIT1004 1 row 1 col (numeric)

1

statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 222 column 1
operands : em, *LIT1005, _TEM1001,

em 0 row 0 col (type ?, size 0)


*LIT1005 1 row 1 col (numeric)

2

_TEM1001 1 row 1 col (numeric)

0

statement : ASSIGN at line 222 column 1
ERROR: (execution) Invalid operand to operation.

operation : J at line 222 column 1
operands : _TEM1001, *LIT1006, *LIT1007

_TEM1001 1 row 1 col (numeric)

0

*LIT1006 1 row 1 col (numeric)

1

*LIT1007 1 row 1 col (numeric)

1

statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : MAX at line 222 column 1
operands : jcol

jcol 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : J at line 222 column 1
operands : j, *LIT1015, *LIT1016

j 0 row 0 col (type ?, size 0)


*LIT1015 1 row 1 col (numeric)

1

*LIT1016 1 row 1 col (numeric)

0

statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : J at line 222 column 1
operands : j, _TEM1001, *LIT1017

j 0 row 0 col (type ?, size 0)


_TEM1001 1 row 1 col (numeric)

0

*LIT1017 1 row 1 col (numeric)

0

statement : ASSIGN at line 222 column 1
ERROR: DO expression not given value.

statement : DO at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : J at line 222 column 1
operands : j, *LIT1023, *LIT1024

j 0 row 0 col (type ?, size 0)


*LIT1023 1 row 1 col (numeric)

1

*LIT1024 1 row 1 col (numeric)

0

statement : ASSIGN at line 222 column 1
ERROR: DO expression not given value.

statement : DO at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 222 column 1
operands : d2j, $SUB0001,

d2j 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 222 column 1
operands : rj, $SUB0001, $SUB0001

rj 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : PROBCHI at line 222 column 1
operands : d2, df

d2 0 row 0 col (type ?, size 0)


df 0 row 0 col (type ?, size 0)


statement : ASSIGN at line 222 column 1
NOTE: Non-portable document will be produced. The current settings of FORMCHAR use nonstandard
line-drawing characters and the resulting output file will not render correctly unless all
readers of the document have the SAS Monospace font installed. To make your document
portable, issue the following command:
OPTIONS FORMCHAR="|----|+|---+=|-/\<>*";

ERROR: Operand j does not have a value.

statement : PUT at line 222 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 222 column 1
operands : rj, $SUB0001, $SUB0001

rj 0 row 0 col (type ?, size 0)


statement : PUT at line 222 column 1
ERROR: Operand d2 does not have a value.

statement : PUT at line 222 column 1
ERROR: Operand df does not have a value.

statement : PUT at line 222 column 1
ERROR: Operand p does not have a value.

statement : PUT at line 222 column 1
223
224 run;
NOTE: Module MAIN is undefined in IML; cannot be RUN.

Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy
Note that I did not have an INPUT statement, you need to remove that as well. Your error starts there as well.
Occasional Contributor
Posts: 12

Re: Little's MCAR macro

Thanks. Took out the input statement. Here is the log again.

 



NOTE: Libref HINTS was successfully assigned as follows:
Engine: V9
Physical Name: H:\Hints\RM\EHR Manuscript
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 6:30.92
cpu time 12.54 seconds

 


NOTE: There were 3285 observations read from the data set HINTS.HINTS5_CYCLE1_INTERNAL.
NOTE: The data set WORK.ONE has 3285 observations and 543 variables.
NOTE: DATA statement used (Total process time):
real time 21.04 seconds
cpu time 0.20 seconds

 

NOTE: There were 3285 observations read from the data set WORK.ONE.
NOTE: The data set WORK.ONE has 3285 observations and 543 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.06 seconds
cpu time 0.04 seconds


WARNING: All observations are missing for variable female_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable age_3cat_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable race_4cat_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable income_4cat_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable education_4cat_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable occupation_2cat_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable MaritalStatus_3cat_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable BornInUSA_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable speak_wm. This variable will be excluded from
the analysis.
WARNING: All observations are missing for variable HealthInsurance_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable RegularProvider_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable ownership_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable RUC2013_3cat. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable UseInternet_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable Dialup_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable Broadbnd_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable cell_wm. This variable will be excluded from
the analysis.
WARNING: All observations are missing for variable wifi_wm. This variable will be excluded from
the analysis.
WARNING: All observations are missing for variable tablet_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable smartph_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable cellph_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable GenHealth_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable MaintainEMR_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable HCPaccess_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable HCPencourage_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable OwnAccess_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable FamilyAccess_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMRsafe_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable EMR_Appt_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable EMR_RefillMeds_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_paperwork_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_correction_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_MessageHCP_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_results_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_MonitorHealth_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_DownloadHealth_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_Addinfo_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_MakeDecision_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_labs_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable EMR_meds_wm. This variable will be excluded
from the analysis.
WARNING: All observations are missing for variable EMR_HealthProbs_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_allergies_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_VisitSummary_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_ClinNotes_wm. This variable will be
excluded from the analysis.
WARNING: All observations are missing for variable EMR_Immunizations_wm. This variable will be
excluded from the analysis.
ERROR: Fewer than two analysis variables.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.EMCOV may be incomplete. When this step was stopped there were 0
observations and 48 variables.
WARNING: Data set WORK.EMCOV was not replaced because this step was stopped.
NOTE: PROCEDURE MI used (Total process time):
real time 0.11 seconds
cpu time 0.07 seconds


NOTE: IML Ready
WARNING: Data set WORK.EMCOV is empty.

statement : USE at line 445 column 1
WARNING: End of File reached.

statement : READ at line 445 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 445 column 1
operands : em, *LIT1004,

em 0 row 0 col (type ?, size 0)


*LIT1004 1 row 1 col (numeric)

1

statement : ASSIGN at line 445 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 445 column 1
operands : em, *LIT1005, _TEM1001,

em 0 row 0 col (type ?, size 0)


*LIT1005 1 row 1 col (numeric)

2

_TEM1001 1 row 1 col (numeric)

0

statement : ASSIGN at line 445 column 1
ERROR: (execution) Matrix has not been set to a value.

operation : * at line 445 column 1
operands : mu, Dj

mu 0 row 0 col (type ?, size 0)

Dj 46 rows 1 col (numeric)

statement : ASSIGN at line 445 column 1
ERROR: (execution) Invalid argument to function.

operation : PROBCHI at line 445 column 1
operands : d2, df

d2 1 row 1 col (numeric)

0

df 1 row 1 col (numeric)

-45

statement : ASSIGN at line 445 column 1
ERROR: Operand p does not have a value.

statement : PUT at line 445 column 1
446
447 run;
NOTE: Module MAIN is undefined in IML; cannot be RUN.

 

SAS Output

The SAS System

Number of Observed Variables =   0                                                               
Number of Missing Data Patterns =                                                                
Summary of Missing Data Patterns (0 = Missing, 1 = Observed)                                     
                                                                                                 
Frequency | Pattern | d2j                                                                        
                                                                                                 
                                                                                                 
                                                                                                 
Little's (1988) Chi-Square Test of MCAR 
Occasional Contributor
Posts: 12

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy

Sorry, here is the output

SAS Output

The SAS System

Number of Observed Variables =  46                                                               
Number of Missing Data Patterns =   1                                                            
                                                                                                 
Summary of Missing Data Patterns (0 = Missing, 1 = Observed)                                     
                                                                                                 
Frequency | Pattern | d2j                                                                        
                                                                                                 
  3285    |  0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 | 0.000000                                                                               
                                                                                                 
Sum of the Number of Observed Variables Across Patterns (Sigma psubj) =     1                    
                                                                                                 
Little's (1988) Chi-Square Test of MCAR                                                          
                                                                                                 
Chi-Square (d2)      =      0.000                                                                
df (Sigma psubj - p) =        -45          
Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy

Looks like there's an issue with your data, the macro is working now. See all the error messages about missing data. Check if they're numeric as required or if there's something wrong with the data.

Occasional Contributor
Posts: 12

Re: Little's MCAR macro

The dataset is fine, ran proc contents and also ran frequency, logistic regression

 


proc surveyfreq data = hints.hints5c1_working1 varmethod=jackknife;
weight person_finwt0;
repweights person_finwt1-person_finwt50 / df=49 jkcoefs=0.98;
table GenHealth_r/ row cl;
run;

 

SAS Output

The SAS System

The SURVEYFREQ Procedure
Data SummaryNumber of ObservationsSum of Weights
3285
247789111

 

Variance EstimationMethodReplicate WeightsNumber of Replicates
Jackknife
HINTS5C1_WORKING1
50

 

Table of GenHealth_rGenHealth_r Frequency WeightedFrequency Std Err ofWgt Freq Percent Std Err ofPercent 95% Confidence Limitsfor Percent-901Total
3823452675673230.94650.22900.48641.4066
2662203680066309005782.19901.247179.692984.7050
58541763778297170216.85461.199314.444519.2646
32852477891114.19158E-6100.000  
Super User
Posts: 23,700

Re: Little's MCAR macro

Posted in reply to sherineeltoukhy

Are your variables numeric?


Try running it with a smaller variable list and see if it works. 

Occasional Contributor
Posts: 12

Re: Little's MCAR macro

Yes, data are numeric. I will create another data set and drop all the variables that I am not using and see if it runs. I will keep you posted. Many thanks for your help. Really appreciate it.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 16 replies
  • 204 views
  • 6 likes
  • 5 in conversation