BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
No_ABD_for_me
Obsidian | Level 7

Hi,

 

I am having difficulty with the SAS syntax for my dataset. I am attempting to run Little's MCAR test on my data using the code at the very bottom of this post. However, I am continuously seeing this result

 

No_ABD_for_me_0-1629393391066.png

 

and this error message in the log "Physical file does not exist, /pbr/biconfig/940/Lev1/SASApp/rs.t1."

 

I am thinking the issue lies in the path for the dataset. I have the dataset uploaded into the SAS ODA cloud (i.e., on the web browser) in the library rs, and the name of the file is t1. For reference, I am using a Mac OS. Can someone please help? #DissertationDesperation

 

%macro mcartest;

/* SPECIFY FILE PATH FOR THE INPUT DATA */

%let datafile = "rs.t1"; 

/* SPECIFY INPUT DATA VARIABLE LIST */

%let varlist = pedq pals iai safe se ogpa;

/* SPECIFY VARIABLE SET FOR THE MCAR TEST */

%let testvars = pedq pals iai safe se ogpa;

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you are using a browser than most likely you are using SAS/Studio to submit your SAS code to the SAS server.  SAS/Studio has ways for you to upload files and ways for you to see the files in its user interface.  Once you upload the file check the properties of it and it should show you the full path the file that you can use.

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

Specify the fully qualified name of the file. 

So if the file is in your home directory the change could be as small as:

%let datafile = "~/rs.t1"; 

Just make sure the path is to where the file is on the server where SAS is running.  Not where a copy of the file might be on your Mac. 

No_ABD_for_me
Obsidian | Level 7

Thanks so much for your prompt response. Can you provide some examples of servers so that I can be fully aware of your point of reference? I didn't download anything for this version of SAS, so there isn't any location where I can find SAS running other than on my web browser.

Tom
Super User Tom
Super User

If you are using a browser than most likely you are using SAS/Studio to submit your SAS code to the SAS server.  SAS/Studio has ways for you to upload files and ways for you to see the files in its user interface.  Once you upload the file check the properties of it and it should show you the full path the file that you can use.

No_ABD_for_me
Obsidian | Level 7

Thanks. This is what I see when I open the properties for my dataset. Which would be the path?

No_ABD_for_me_0-1629396323606.png

 

Tom
Super User Tom
Super User

Your SAS code does not want a SAS dataset. It wants a text file it can read to create a SAS dataset.  

If you already have a SAS dataset then you will need different code.

No_ABD_for_me
Obsidian | Level 7

Oh, I see! So I would probably need to convert to a txt file from the dataset I have and then upload that. Thanks so much!

tom_grant
SAS Super FREQ
I haven't looked through the entire code but assuming t1 is a SAS dataset & you have a SAS library named rs on SAS OnDemand for Academics - you can just modify your code a little bit:
1. Remove the quotation marks (") the %let datafile statement (%let datafile = rs.t1;)
2. Change the following code below where it says not to make changes:
data one;
infile &datafile ;
input &varlist;
change to
data one;
set &datafile (keep = &varlist);

Let me know if this works - I tested it on SASHELP.cars & it appeared to work
No_ABD_for_me
Obsidian | Level 7

Unfortunately, this didn't work on my dataset. However, converting to a txt file and then uploading that into my SAS before finding the path ("location") using the "properties" of the txt file was a success! Thanks so much!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1269 views
  • 0 likes
  • 3 in conversation