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

Hi all, 

 

I am trying to run this macro for Little's MCAR test: http://www.appliedmissingdata.com/littles-mcar-test.sas

 

However, I am getting error messages saying data are invalid for each of my variables... 

 

I tried having the dat file as comma vs tab delimited, with and without the first row of variable names, double-checked that there are no non-numerical values... Still getting an error message. 

 

What else do you think the cause of error can be? 

 

Thank you in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Thanks for posting the log.

 

  1. The number of variables in dataset WORK.ONE is determined by the number of variable names specified in the INPUT statement, i.e., in macro variable VARLIST. Does this list contain 175 or 349 "words" (separated by blanks)? For testing purposes, you may want to truncate this variable list (and the list in macro variable TESTVARS correspondingly) to less than 10 items and try to achieve an error-free log before going further.
  2. The error message "Variable I not found" from PROC MI suggests that your variable list in macro variable TESTVARS contains the name "I" (or "i"). You would need to name this variable differently (e.g., _i) because macro MCARTEST uses a variable i as an index variable of a DO loop. There might be more name conflicts (j, k, ...) -- see program code in the macro.

View solution in original post

8 REPLIES 8
Quentin
Super User

Hi,

 

I suggest you turn on options MPRINT, run the macro, and review the log.  The macro generates several steps.  Which step does the error occur in?  What does the error message say?  

 

The macro was written to analyze one specific file, 

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

Do you have that data file in c:\data?

 

If you can't see what's happening from the log, I suggest you post the log. 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
FreelanceReinh
Jade | Level 19

Hi @Amanda_Lemon,

 

With the example values for &datafile and &varlist given in the code, the macro uses a simple method of reading the raw data (rather than accepting a SAS dataset as input, which I think is more common):

infile &datafile;
input &varlist;

Hence, either your raw data file needs to be

  • space-delimited
  • without variable names
  • containing only numeric values (readable without specifying informats)
  • representing missing values with single periods (.)

or you need to add options, informats, etc. needed to read your raw data to the values specified in the %LET statements for datafile or varlist.

 

Example:

%let datafile = 'C:\yourfolder\yourfile.csv' dsd missover;

for a comma-separated file with missing values represented by periods or blanks or null strings.

Amanda_Lemon
Quartz | Level 8

Thank you for your replies! I followed FreelanceReinhard's recommendation and added

dsd missover

to the datafile line. My raw file is comma-delimited, periods for missing data, no variable names. The number of error messages decreased but no all... I am including the log below. The program gets the # of observations right. However, the # of variables is 175, not 349... 

 

NOTE: A byte-order mark in the file "C:\Users\Desktop\Data_READY_3.dat" (for fileref "#LN00147") indicates that the data is encoded in
      "utf-8".  This encoding will be used to process the file.
NOTE: The infile "C:\Users\Desktop\Data_READY_3.dat" is:
      Filename=C:\Users\Desktop\Data_READY_3.dat,
      RECFM=V,LRECL=131068,File Size (bytes)=466817,
      Last Modified=31Mar2020:00:48:29,
      Create Time=31Mar2020:00:48:29

NOTE: 1274 records were read from the infile "C:\Users\Desktop\Data_READY_3.dat".
      The minimum record length was 355.
      The maximum record length was 383.
NOTE: The data set WORK.ONE has 1274 observations and 349 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds



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


ERROR: Variable I not found.
NOTE: PROCEDURE MI used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.


NOTE: IML Ready
ERROR: I is not in the scope of variables for the data set.

 statement : READ at line 3482 column 1
ERROR: File WORK.EMCOV.DATA does not exist.

 statement : USE at line 3482 column 1
ERROR: I is not in the scope of variables for the data set.

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

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

em      0 row       0 col     (numeric)


*LIT1004      1 row       1 col     (numeric)

         1

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

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

em      0 row       0 col     (numeric)


*LIT1005      1 row       1 col     (numeric)

         2

_TEM1001      1 row       1 col     (numeric)

         0

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

 operation : J at line 3482 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 3482 column 1
ERROR: (execution) Matrix has not been set to a value.

 operation : MAX at line 3482 column 1
 operands  : jcol

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


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

 operation : J at line 3482 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 3482 column 1
ERROR: (execution) Matrix has not been set to a value.

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

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


_TEM1001      1 row       1 col     (numeric)

       175

*LIT1017      1 row       1 col     (numeric)

         0

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

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

 operation : J at line 3482 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 3482 column 1
ERROR: DO expression not given value.

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

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

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


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

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

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


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

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

D2      0 row       0 col     (numeric)


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


 statement : ASSIGN at line 3482 column 1
ERROR: Operand j does not have a value.

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

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

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


 statement : PUT at line 3482 column 1
ERROR: Operand D2 does not have a value.

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

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

 statement : PUT at line 3482 column 1
3483
3484  run;
NOTE: Module MAIN is undefined in IML; cannot be RUN.
3485
3486  quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.14 seconds
      cpu time            0.07 seconds


 

FreelanceReinh
Jade | Level 19

Thanks for posting the log.

 

  1. The number of variables in dataset WORK.ONE is determined by the number of variable names specified in the INPUT statement, i.e., in macro variable VARLIST. Does this list contain 175 or 349 "words" (separated by blanks)? For testing purposes, you may want to truncate this variable list (and the list in macro variable TESTVARS correspondingly) to less than 10 items and try to achieve an error-free log before going further.
  2. The error message "Variable I not found" from PROC MI suggests that your variable list in macro variable TESTVARS contains the name "I" (or "i"). You would need to name this variable differently (e.g., _i) because macro MCARTEST uses a variable i as an index variable of a DO loop. There might be more name conflicts (j, k, ...) -- see program code in the macro.
Amanda_Lemon
Quartz | Level 8
Thank you so much! The problem was in the I variable. I renamed it, and the macro worked! Thanks again!
Amanda_Lemon
Quartz | Level 8

Just wanted to ask about one more thing -- as I was examining the log, there is a notice "NOTE: Module MAIN is undefined in IML; cannot be RUN." Is this a problem? Why did this notice occur? I do get results even with this notice. 

FreelanceReinh
Jade | Level 19

@Amanda_Lemon wrote:

Just wanted to ask about one more thing -- as I was examining the log, there is a notice "NOTE: Module MAIN is undefined in IML; cannot be RUN." Is this a problem? Why did this notice occur? I do get results even with this notice. 


I suspect that you just need to replace the run; at the bottom of your code by quit; to get rid of this note, but I can't test it because I don't have a SAS/IML license. There is no module defined in the macro (this would be indicated by a START and a FINISH statement), which is why the RUN statement attempts to run a module of the default name "main" -- but this doesn't exist either, hence the note in the log.

Amanda_Lemon
Quartz | Level 8
That was it! Thank you so much!!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

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
  • 1273 views
  • 4 likes
  • 3 in conversation