290 likes | 415 Views
SPSS Class Notes Entering Data. 1.0 Demonstration and explanation We will start with inputting an Excel file. The variable names are on the first line of the Excel file.
E N D
SPSS Class NotesEntering Data • 1.0 Demonstration and explanation • We will start with inputting an Excel file. The variable names are on the first line of the Excel file. • File Open Data from "Files of type", select Excel .xls format select File: c:\spss\hs0.xlsOpen check "Read variable names from the first row of the data" click onOK
A comma-separated-values (.csv) format data file is a text data file and can be read in as follows. The variable names are on the first line of our data file hs0.csv. The same procedure will also work with tab-delimited data files.
File Read Text Data from "Files of type:" select All Files(*.*) select File: c:\spss\hs0.csvOpen click on "Next..." on step 2 of 6, click on "yes"to the question "Are variable names included at the top of your file?" You can accept all other defaults and continue clicking on "next" through the remaining steps click on "Finish..."
The other type of commonly used ASCII data format is fixed format. It always requires a codebook to specify which column corresponds to which variable. Here is small example of this type of data with a codebook. One way of inputting this type of data is through syntax editor.
195 094951 • 26386161941 • 38780081841 • 479700 870 • 56878163690 • 66487182960 • 786 069 0 • 88194193921 • 98979090781 • 107868180801
variable namecolumn numberid1-2a • 13-4 • t15-6 • Gender7 • a28-9 • t2 10-11 • tgender12
You will need to open a new SPSS syntax editor into which you can type the following code. Remember that each command in SPSS must end in a period (.). • File New Syntax • data list fixed file="c:\spss\schdat.fix" / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12. list.
Using syntax editor, we can also input data directly. You can copy and paste the syntax below to the syntax editor and run it. Notice the difference in syntax between a numeric variable and a character variable.
data list list /id female race ses * schtype (A3) prog read write math science socst. begin data. • 147 1 1 3 pub 1 47 62 53 53 61 • 108 0 1 2 pub 2 34 33 41 36 36 • 18 0 3 2 pub 3 50 33 49 44 36 • 153 0 1 2 pub 3 39 31 40 39 51 • 50 0 2 2 pub 2 50 59 42 53 61 • 51 1 2 1 pub 2 42 36 42 31 39 • 102 0 1 1 pub 1 52 41 51 53 56 • 57 1 1 2 pub 1 71 65 72 66 56 • 160 1 1 2 pub 1 55 65 55 50 61 • 136 0 1 2 pub 1 65 59 70 63 51 • end data.
Last but not least, here is how to open an SPSS data file. • File Open Data select File: c:\spss\hs0.savOpen
2.0 Syntax version • * read in an excel (.xls) file. • get data • /type=xls • /file = 'c:\spss\hs0.xls' • /delimiters = "," • /firstcase = 2 • /variables =
v1 f1.0 • v2 f3.2 • v3 f1.0 • v4 f1.0 • v5 f1.0 • v6 a10 • v7 f2.1 • v8 f2.1 • v9 f2.1 • v10 f2.1 • v11 f2.1. execute.
* read in a filed format ascii file. data list fixed file "c:\spss\schdat.fix" / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12. list. * input data directly using the syntax editor. data list list /id female race ses * schtype (a3) prog read write math science socst. begin data. 147 1 1 3 pub 1 47 62 53 53 61 108 0 1 2 pub 2 34 33 41 36 36 18 0 3 2 pub 3 50 33 49 44 36 153 0 1 2 pub 3 39 31 40 39 51 50 0 2 2 pub 2 50 59 42 53 61 51 1 2 1 pub 2 42 36 42 31 39 102 0 1 1 pub 1 52 41 51 53 56 57 1 1 2 pub 1 71 65 72 66 56 160 1 1 2 pub 1 55 65 55 50 61 136 0 1 2 pub 1 65 59 70 63 51 end data. get file 'c:\spss\hs0.sav'.
SPSS Learning ModuleHow to read raw data into SPSS • This module introduces the reading of raw data files into SPSS. It does not show how to read all possible data formats, but aims to show how to read many common file formats
1. Comma delimited data, inline • The example below illustrates how you can read comma delimited data inline. Inline data refers to data that is included as part of a syntax program between begin data and end data commands. This is a very convenient way to read data when your data file is small and/or when you want to be sure to keep your data and the program for reading your data together.
The data list command indicates that we are going to read a data file. The keyword list (the second one) indicates that there is one observation per line of data and that each variable is separated by spaces and/or commas. Following the / is the list of the variable names. Since make is a string (alphanumeric) variable, we use the (A15) to tell SPSS that make is a string variable (with a length of 15). The data appear between the begin data and end data commands, and the list command is used to see if the data were read correctly.
DATA LIST LIST • / make (A15) mpg weight price . • BEGIN DATA. • "AMC Concord",22,2930,4099 • "AMC Pacer",17,3350,4749 • "AMC Spirit",22,2640,3799 • "Buick Century",20, 3250,4816 • "Buick Electra",15,4080,7827 • END DATA. • LIST.
From the output below, it looks like the data were read properly. You might wonder if the quotations marks around the makes of car were needed. SPSS treats commas and spaces as valid delimiters (separators) in this mode of input, so the quotes are necessary. Otherwise, SPSS would think that AMC was the make and Concord was the mpg for the first observation.
MAKE MPG WEIGHT PRICE • AMC Concord 22.00 2930.00 4099.00 • AMC Pacer 17.00 3350.00 4749.00 • AMC Spirit 22.00 2640.00 3799.00
Space delimited data, inline • Reading space delimited data is basically the same as reading a comma delimited file. As you see below, the program is identical to the one above, but the data are separated by one or more spaces instead of commas. We will omit showing the output from this command.
Space delimited data, inline • DATA LIST LIST • / make (A15) mpg weight price . • BEGIN DATA. • "AMC Concord" 22 2930 4099 • "AMC Pacer" 17 3350 4749 • END DATA. • LIST.
Comma delimited data from an external file • When you have a larger file, it is often more convenient to read the data from an external data file. The syntax of reading data from an external data file is not much more complicated than reading from inline data. The example below shows that you use file="auto1.txt" (in this example) to tell SPSS that you want to read the data from the file called auto1.txt. When you run this, change auto1.txt to be the name of your raw data file (for example, "c:\mydata.txt"). We will omit showing the output of these commands.
DATA LIST LIST FILE="auto1.txt" / make (A15) mpg weight price. • LIST.
SPSS Learning ModuleHow to input data into the SPSS data editor • Introduction • This page shows the basics of entering data into the SPSS data editor. The SPSS data editor can be a good choice for entering your data. It has a friendly interface that resembles an Excel spreadsheet and by entering the data directly into SPSS, you don't need to worry about converting the data from some other format into SPSS. For example, you might enter your data in Excel, and then try to convert it to SPSS and find out that you used the latest version of Excel, but your version of SPSS has trouble reading the latest Excel files. • Below is a screen snapshot of what the SPSS data editor looks like when you start SPSS. As you see, it does look like an Excel spreadsheet. In this editor, the columns will represent your variables, and the rows will represent your observations (sometimes called records, subjects or cases).
SPSS Learning ModuleHow to input data into the SPSS data editor
Let's illustrate how to enter data into the SPSS data editor using the data file below. • make mpg weight price AMC Concord 22 2930 4099 AMC Pacer 17 3350 4749 AMC Spirit 22 2640 3799 Buick Century 20 3250 4816 Buick Electra 15 4080 7827
First, you need to tell SPSS the names of your variables. You can double click on the column heading (shown with the arrow below for the first column). That permits you to enter information about the variable for that column.