Reading a .xls file or .sav file PreviousNext
Mplus Discussion > Structural Equation Modeling >
Message/Author
 Renata Estrella posted on Friday, December 09, 2005 - 7:43 am
Does Mplus read data from excell or from spss?
 Linda K. Muthen posted on Friday, December 09, 2005 - 8:03 am
No. Data must be in as ASCII file (text file).
 Renata Estrella posted on Friday, December 09, 2005 - 8:06 am
Thanks!
 Fernando Terrés de Ercilla posted on Thursday, November 23, 2006 - 11:44 pm
I've just written an SPSS macro (include file) to automatically convert SPSS data into a data file (.dat) and Mplus program (.inp) that can be used in Mplus. If somebody is interested, let me know (alternatively, I could post it here).
 Linda K. Muthen posted on Friday, November 24, 2006 - 9:28 am
You can post it here as long as it fits in a single post. Otherwise, it should be by request.
 Zhiyong Yang posted on Thursday, December 07, 2006 - 5:51 pm
Fernando,

Could you please send your SPSS macro to me ASAP? Many thanks! I am finding a very hard time to convert my SPSS data into a .dat file that can be accepted by MPlus.

Thanks again.

Zhiyong
zyang@jmsb.concordia.ca
 Linda K. Muthen posted on Friday, December 08, 2006 - 9:58 am
Have you tried opening the file in the SPSS editor and using the SAVE AS function? It has been reported to me that this is possible in SPSS. There are issues that you need to change the missing values from . to a user-specified value. Otherwise, the .'s are saved as blanks.
 Linda K. Muthen posted on Sunday, March 04, 2007 - 9:46 am
I understood from Fernando that his macro did not work. It is my understanding that you open an SPSS file in their editor and save as either a text file or a file delimited by tabs, blanks, or commas. It is unclear from you post whether your error messages come from trying to create an ASCII file or from using the ASCII file.
 Todd B. Kashdan posted on Tuesday, June 26, 2007 - 9:23 am
Fernando,

Could you send me your SPSS macro as well? I am not able to convert my file to an acceptable .dat version yet.

gratefully,

Todd B. Kashdan, Ph.D.
Assistant Professor
Department of Psychology
George Mason University
tkashdan@gmu.edu
 Linda K. Muthen posted on Tuesday, June 26, 2007 - 9:30 am
My understanding is that you open your SPSS file and use the Save As function to save it as a text file. I don't think the macro worked.
 Mogens Fenger posted on Friday, August 15, 2008 - 4:45 am
It is sometimes tedious to convert SPSS files, but in fact is should be easy. When I save a SPSS file as a .dat file I include the headings. Then I use TextPad (on the net) to open the dat-file, copy the headings into Mplus NAMES ARE, remove the headings from the TextPad file, and then very important: commas are used in the data as decimal points but should be dots. This is easily corrected in TextPad. The file should then be OK.
 Ioanna Vrouva posted on Thursday, September 11, 2008 - 7:13 am
Dear all,
I have managed to save my SPSS file as a ASCII file (.dat). However,I am somewhat unclear about the MVs issue. At first I deleted all MVs before converting the SPSS file into an MPlus data file but what is the best way of keeping MVs in a CFA? Recode all of them as an X number in SPSS file first and then convert to the MPlus data file?
thank you very much.
Ioanna
 Linda K. Muthen posted on Thursday, September 11, 2008 - 11:33 am
If by MV you mean missing value, save the full data set with a specified missing value flag. The use the MISSING option in Mplus to specify the missing value flag(s).
 JackBox posted on Friday, September 19, 2008 - 4:40 am
I have converted my spss data to .dat file. Missing cases are marked as 999 and I've changed commas to dots. The values are delimited by tabs. From my point of view everything should be ok.

For some reason the analyze is now done only to half of the data so that only 50% of the both groups data is used. What is the reason for this? How can I fix this problem?
 JackBox posted on Friday, September 19, 2008 - 5:18 am
I've found the reason: In the VARIABLE list there was one extra variable which was earlier made (and used) with DEFINE command. In the current input this extra variable was not needed anymore and I took the DEFINE command away, but forget to delete this extra variable from the variable list.

The problem is now solved, but why did this use of 50% of the data happend?
 Linda K. Muthen posted on Saturday, September 20, 2008 - 4:48 pm
If you have too variables on the NAMES statement, the program would have needed to read two lines in the data file to find the correct number of pieces of information. If you create a new variable in DEFINE, it should not be placed on the NAMES statement. It should be placed on the USEVARIABLES list.
 Anna Sims posted on Friday, October 24, 2008 - 1:15 am
Hi Fernando,
Would you be able to email me the macro as well?

Thanks,

Anna
as520@york.ac.uk
 Tim Wind posted on Friday, March 19, 2010 - 6:27 am
Hi all,

I have a problem converting my SPSS data into MPlus as well. When I convert the SPSS data into a Asci file (.dat), I lose the variable names.
1. How can I solve this problem?
2. Can I only use the names x, y, w, or clus (cluster) for variables?

Thank you in advance,

Best, Tim
 Linda K. Muthen posted on Friday, March 19, 2010 - 6:35 am
I am not sure what you mean by lose the variable names. The NAMES option of the VARIABLE command is used to give the variable names. Variable names must begin with a letter. They can contain only letters, numbers, and the underscore symbol.
 JackBox posted on Friday, March 19, 2010 - 7:12 am
If you use SPSS18, try to save as "tab delimited" and check the "Write variable names to spreadsheet" box. That should solve the first problem. In the data file the first row will be the variable names from SPSS.

In Mplus variable names can not be longer than 7 marks in addition to Lindas notes.
 finnigan posted on Friday, March 19, 2010 - 7:53 am
There is a piece of software that converts SPSS files to an MPLUS format. Its called N2MPLUS.
Here's the link
http://www.danielsoper.com/n2mplus/

It might be of use.
 Keri Pinna posted on Sunday, August 08, 2010 - 7:28 pm
I'm new to MPlus and am using N2MPlus to convert my SPSS data. For some reason the last case in my SPSS file is not being read into the converted file. Any ideas on why that might be? I was previously able to copy and paste data from that final case into the new file, but now that no longer works.
 Linda K. Muthen posted on Monday, August 09, 2010 - 6:31 am
I am not familiar with N2Mplus. You should check with whoever makes it to see if they know of a solution.
 Peter Elliott posted on Monday, August 23, 2010 - 5:42 pm
N2Mplus is a great program, but it does drop the last case in a SPSS data file. You need to add a dummy row to the end of your SPSS data file. It doesn't matter what values you put into this row as N2Mplus ignores it anyway.

peter
 Keri Pinna posted on Friday, September 17, 2010 - 12:13 pm
Peter -

Thanks for the tip. I added the dummy variable and N2MPlus is now reading all of my variables (unfortunately, when I contacted the author via the N2MPlus website, I received no reply).

My next issue is that MPlus is not consistently reading all of the cases from the N2MPlus file. I have tried the standard checking for missing values and ensuring that lines are of equal length. Any other suggestions? It was reading all of the variables until I revised the file as I needed to calculate new variables (because I'm still new to MPlus, I calculated them in SPSS and reconverted to MPlus using N2MPlus).
 Linda K. Muthen posted on Friday, September 17, 2010 - 2:14 pm
Please send your input, data, output, and license number to support@statmodel.com.
 EFried posted on Tuesday, January 17, 2012 - 3:24 pm
Dear Dr. Muthén.

If I save SPSS v.20 data via "save as -> fixed ASCII .dat", the means in MPLUS are completely messed up.

If I save SPSS v.20 data via "save as -> tab delimited .dat", things seem ok. (I'd love if you added a section to your handbook about this. Maybe I'm just blind. What is the method you recommend?)

However, the means are slightly different from the SPSS file.

SPSS 2.452, 5,424, 5.826, 6.238, 5.591
MPLUS 2.394, 5.469, 6.015, 6.479, 5.768

To make sure I did nothing wrong, I double checked descriptive statistics and frequencies in SPSS, rounded every variable in SPSS again just to make sure they have no digits after comma, and double checked all missings (all have -999, and are correctly identified in MPLUS).

In MPLUS I simply use "sampstat" to get means.

What could be the reason for this?

Thank you
Torvon
 Linda K. Muthen posted on Tuesday, January 17, 2012 - 7:02 pm
I am not sure what you mean by fixed ASCII.dat. You can save an SPSS file as txt, comma delimited, or tab delimited. See the DATA command in the user's guide where the type of data Mplus can read is described.

Mplus uses the full sample size for the means. SPSS uses all available data for each variable so the sample size can vary for each variable depending on the amount of missing data.
 EFried posted on Wednesday, January 18, 2012 - 9:51 pm
Linda, thank you.

(1) Data
"Fixed ASCII" is an option in SPSS, screenshot here:
http://www.revelation-of-silence.com/wp-content/uploads/2012/01/spss_save.png

(2) Means
I didn't know that. The differences are quite big though (5.8 vs. 6.0 for N>750!), I don't understand it. If I have four values, 1=1.0, 2=2.0, 3=3.0 and 4=missing, the true mean is 2.0, right? How can they be different?
What I did now: sampstat using all 5 measurement points, and sampstat only using one measurement. The second one calculation in MPLUS is much closer to the SPSS mean than the first calculation.

Also: which mean value do I report in a paper?

Thank you
Torvon
 Linda K. Muthen posted on Thursday, January 19, 2012 - 6:26 am
I suspect when you use fixed ASCII, you are reading the data as free format and forgetting to use the FORMAT option.

You should report the sample statistics that the analysis is based on. If you do your analysis in Mplus, ask for SAMPSTAT in the MODEL command or TYPE=BASIC.
 John Mahoney posted on Tuesday, February 12, 2013 - 12:37 am
Any suggestions about how to convert SPSS data to be used with the Mac version of Mplus?

I've tried converting into a text file (.dat) and everything 'looks' in place (compared to other data sets I've used on Windows), but I continue to receive an 'error' message saying I have no observations.

I know my input is correct because I've tried it on example data sets (again, which look highly similar to the one I've generated). However, I still can't analyse my data set.

Help please!!

John
 Linda K. Muthen posted on Tuesday, February 12, 2013 - 6:10 am
SPSS seems to be saving the data as unicode. Open the data file in the Mplus editor. You may see an invalid characted at the beginning of the first record. If so, delete it and save the data. Another problem could be blanks in the data set. If you can't solve this, send the input, data, output, and your license number to support@statmodel.com.
 Ninni Persson posted on Wednesday, May 08, 2013 - 1:43 pm
Dr. Muthen,

I am having such a hard time converting SPSS data to m+. When I open the .dat file
in m+ to edit it, I find some variables having 6 decimals (as in the original file),
and others 10. I have to edit everything by hand in mplus. Is there a more efficient
way of dealing with converting data from SPSS (19)?

Further, when I run mplus script to check that the means are ok, without specifying missing values, I get descriptives for 143 observations. I have 144 in my dataset. When I enter a line for missing values (-99), I get the following message. NO CONVERGENCE IN THE MISSING DATA ESTIMATION OF THE SAMPLE STATISTICS. Also, I get a message about having only 72 observations. I have few missing cases and my data is MCAR. What can be done about this? Is something wrong with coding of missing values?

Best
Ninni



Title:

Entering data from .dat file

Data:

File is forMplus19.dat;

Variable:

Names are

93 variables

;

MISSING are all(999);

Analysis:

Type = basic;
 Linda K. Muthen posted on Wednesday, May 08, 2013 - 2:12 pm
I am not familiar with converting from SPSS to an ASCII file. This would be a question for SPSS about why they save the decimals differently. It sounds like you may have blanks in the data set if you are getting less observations. I believe that SPSS uses blanks for missing which is not allowed with free format data.
 Ninni Persson posted on Wednesday, May 08, 2013 - 6:05 pm
Hello Linda,

Thank you for input.

One thing that confuses me is that
when I take missing are all (999)
out of my syntax, all 143 cases are analyzed
instead of 72. Do you have any idea?

Best
Ninni
 Linda K. Muthen posted on Wednesday, May 08, 2013 - 6:27 pm
That's because there are no missing values. It sounds like the missing values may be on covariates and cases with missing values on the covariates are excluded. There will be a warning about this in the output. If you can't figure it out, send the files and your license number to support@statmodel.com.
 Nara Jang posted on Sunday, March 23, 2014 - 12:51 am
Dear Dr. Muthen,

I converted SPSS file to text file (save as tab delimited). But whenever I open the text file, all variables are not in the text file. Would you tell me how I can solve this problem.

Also, N2Mplus program has Trojan, so I cannot use this.

Best regards,
Nara Jang
 Linda K. Muthen posted on Sunday, March 23, 2014 - 6:27 am
Have you tried using the file with Mplus?
 Dale Hample posted on Saturday, April 26, 2014 - 9:42 pm
The N of 143 is interesting. I am learning MPlus this weekend and began by converting an SPSS file into a .csv file. I deleted the first row of the .csv, which contained variable names. But the SPSS file had a few missing values. Not realizing the problem, I ran some CFAs in MPlus, and saw that 143 cases were being read, instead of the 270 or so that are actually in the data file.
 Linda K. Muthen posted on Sunday, April 27, 2014 - 6:25 am
I suspect you have blanks in your data set. This is not allowed with free format data. SPSS uses blanks for missing values in some cases.
 Dale Hample posted on Sunday, April 27, 2014 - 7:39 am
You are certainly right. I was just noticing the 143, which an earlier poster in this thread said was where his/her data set choked,too.
 Linda K. Muthen posted on Sunday, April 27, 2014 - 8:28 am
That is just a coincidence.
 Samantha Penney posted on Tuesday, June 03, 2014 - 1:19 pm
I've saved my SPSS file as a .dat file to my desktop and included the following in my syntax:

Data:
File is "DASfile.dat";

However I keep getting the error that it can't be found.

*** ERROR
The number of observations is 0. Check your data and format statement.
Data file: DASfile.dat
*** ERROR
Invalid symbol in data file:
"D1Pr" at record #: 1, field #: 5
 Linda K. Muthen posted on Tuesday, June 03, 2014 - 1:38 pm
It sounds like you have the variable names in the first line. Delete this line.
 Jahnavi posted on Friday, August 29, 2014 - 11:11 am
Hi there! Trying to pick up MPlus and am experiencing problems with the first and simplest step! I have converted an SPSS file to a tab delimited .dat using the SAVE AS function, but when I attempt to open and run basic analysis on it using this input:


title: read data into mplus;

data: file = c1 SPSS example Burnout.dat;

variable: names = burnout loc cope teaching research pastoral;

analysis: type = basic;


I get this error, which I have seen mentioned several times here:

*** ERROR
The number of observations is 0. Check your data and format statement.
Data file: c1 SPSS example Burnout.dat
*** ERROR
Invalid symbol in data file:
"" at record #: 1, field #: 1


There are no missing values to speak of in this data set, I did not save the variable names to the .dat file, I see no sign of unusual characters in my file, and all of my decimals are properly designated with a period. This is the second data set I have attempted to open this way, and the second time I have encountered this problem. What's happening?
 Jahnavi posted on Friday, August 29, 2014 - 12:09 pm
Okay! I figured this out. The "invalid symbol" that the error code is referring to was the tab in front of the first data point, which was automatically inserted when I created the tab delimited file. Why this tab is considered "invalid" when it is part of the tab delimited construct is beyond me. Removing it fixed the problem, though.
 Jahnavi posted on Friday, August 29, 2014 - 12:09 pm
Okay! I figured this out. The "invalid symbol" that the error code is referring to was the tab in front of the first data point, which was automatically inserted when I created the tab delimited file. Why this tab is considered "invalid" when it is part of the tab delimited construct is beyond me. Removing it fixed the problem, though.
 Linda K. Muthen posted on Friday, August 29, 2014 - 1:26 pm
There should not be a tab before the first entry. Delete it and resave the data.
 Gregory Smith posted on Saturday, January 17, 2015 - 7:44 am
After years of running mplus models moved from spss to mplus (I have saved them as .dat files), mplus is no longer finding the files I save (I can still run old files). I get this error message each time: "The file specified for the FILE option cannot be found. Check that this file exists: desktop\ericawh.dat"

Of course I can see the file and open it and everything, so it does seem to exist.

I use version 22 of spss.

The one new thing is that now, when I open the file in Word to remove the variable names, it asks me to select the encoding that makes the document readable and specifies the choice of unicode-8. I have tried that, something called "local encoding," and ASCII and nothing has worked.
 Linda K. Muthen posted on Saturday, January 17, 2015 - 9:22 am
Open the file in Excel and save it as a DOS txt file. I think SPSS now uses Unicode. If you continue to have problems, send the files and your license number to support@statmodel.com.
 Shraddha Kashyap posted on Sunday, February 08, 2015 - 7:42 pm
Hi,

I have tried re-saving an SPSS file into a tab delimited file several times and I've tried running my analyses several times, but mplus6 is reading only 1092 of 1103 cases in my data set.

This has not happened before, and I'm using the same syntax as I have in the past--any suggestions?

thanks!
 Linda K. Muthen posted on Sunday, February 08, 2015 - 8:13 pm
You most likely have blanks in the data set. SPSS uses blanks as a type of missing value flag.
 Walaa Ismael posted on Thursday, June 18, 2015 - 7:48 am
Hi,
Please, I am new at Mplus. I am trying to enter my data set to Mplus. However, I do not know where the problem is. I have continuous dependent (y) and 13 background variables (only one continuous and the other binary and categorical) and 6 latent variables (one categorical and the other binary). This is my code:
TITLE: this is an example of linear regression for continuous dependent and 2 covariates
DATA: FILE IS 'E:\Mplus\Company.B.Coded.csv';
VARIABLE: NAMES ARE y x1-x13 u1-u6;
USEVARIABLES ARE y x1 x2;
MODEL: y ON x1 x2;

I got this error. I have already removed the variables names in the data set:
*** ERROR
The length of the data field exceeds the 40-character limit for free-formatted
data. Error at record #: 1, field #: 1
*** ERROR
The number of observations is 0. Check your data and format statement.
Data file: E:\Mplus\Company.B.Coded.csv

Please help,
 Linda K. Muthen posted on Thursday, June 18, 2015 - 8:50 am
Please send the output, data, and your license number to support@statmodel.com.
 Walaa Ismael posted on Thursday, June 18, 2015 - 9:05 am
Dear Linda,
Thanks for your quick reply.

1- Is this code right? Is what I have done is OK? Please, I would like to make sure that the code is right.
2- I am working in the demo virgin because Mplus software is not in my university software’s. They are trying to get it, but I do not have enough time, so I am trying to run a simple model in demo until they get it.
3- Do you think that the demo virgin is the reason?

Thanks in advance,
walaa
 Linda K. Muthen posted on Thursday, June 18, 2015 - 1:12 pm
It is not because you use the Demo. Try saving the data set as a DOS text file.
Back to top
Add Your Message Here
Post:
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: