Read Data from an External File into SPSS

Deepanshu Bhalla 4 Comments
01. Read SPSS Data Files

Go to File >> Open >> Data >> Select file >> In Files of type box , use drop menu to select SPSS Statistics (*.sav) >> Press Open .



SYNTAX : 
The GET FILE command allows SPSS data files to be read into SPSS .

GET FILE='full path name'.
GET FILE='C:\Program Files\SPSSInc\Samples\English\autoaccidents.sav'.


02. Read SAS data files
Go to File >> Open >> Data >> Select file >> In Files of type box , use drop menu to select SAS (*.sas7bdat) >> Press Open .


SYNTAX : 
The GET SAS DATA command allows SAS data files to be read into SPSS .
GET SAS DATA ='FULL PATH NAME'.
GET SAS DATA ='C:\Deepanshu\Desktop\Data Files\merger.sas7bdat'. 



03. Read Excel data files
Go to File >> Open >> Data >> Select file >> In Files of type box , use drop menu to select Excel (*.xls, *xlsx) >> Press Open .




SYNTAX : 
1. The /TYPE=XLSX command indicates that you are reading an  excel 2007 (xlsx) data files.
2. The /TYPE=XLS command indicates that you are reading an excel 2003 (xls) data files.

Example 1 :


GET DATA
/TYPE=XLSX
/FILE='C:\Deepanshu\Desktop\Data Files\Compare.xlsx' .

Example 2 :
Extract data from a particular sheet in Excel 2003 workbook.


GET DATA
 /TYPE=XLS
/FILE='C:\Deepanshu\Desktop\Data Files\Compare.xls'
/SHEET=name 'Sheet3' .


04. Read Text data files
Go to File >> Open >> Data >> Select file >> In Files of type box , use drop menu to select Text (*.txt, *dat) >> Press Open .





SYNTAX : 
Example 1 : Tab Delimited Files 

The GET TRANSLATE command allows tab data files to be read into SPSS .

GET TRANSLATE FILE="D:\price.txt"
 /TYPE=TAB
  /FIELDNAMES.

OR

GET DATA
  /TYPE=TXT
  /FILE='C:\Deepanshu\color combination.txt'
  /DELCASE=LINE
  /DELIMITERS="\t"
  /ARRANGEMENT=DELIMITED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=  V1 A14.

Here, /DELIMETERS="\t" command indicates that you are reading a tab delimited file.In this example, V1 is variable name and A14 indicates string variable type with width 14.

Example 2 : Space Delimited Files

GET DATA
/TYPE=TXT
/FILE='C:\Deepanshu\salary.txt'
/DELCASE=LINE
/DELIMITERS=" "
/ARRANGEMENT=DELIMITED
/FIRSTCASE=1
/IMPORTCASE=ALL
/VARIABLES = salary DOLLAR8 salbegin DOLLAR8.

Here, /DELIMETERS=" " command indicates that you are reading a space delimited file.In this example, salary and salbegin are variable names and DOLLAR8 indicates dollar variable type with width 8.

For other delimiters , 

/DELIMETERS="," - To specify a comma as a delimeter
/DELIMETERS=";" - To specify a semicolon as a delimeter
/DELIMETERS="\\" - To specify a backslash as a delimeter

05. Read Stata data files
Go to File >> Open >> Data >> Select file >> In Files of type box , use drop menu to select Stata (*dta) >> Press Open .


SYNTAX : 
The GET STATA command allows Stata data files to be read into SPSS .

GET STATA DATA ='full path name'.
GET STATA DATA='C:\Samples\autoaccidents.dta'.
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

4 Responses to "Read Data from an External File into SPSS"
  1. Hi, I am getting this error "Error starting the java virtual machine; unable to open file:" while open excel file is SPSS.
    Can you please help ?

    ReplyDelete
  2. how to know which type of delimeters are present in raw data?

    ReplyDelete
Next → ← Prev