图Open Data Look in: verybasicSP 国腾88= csv gss93subset.crv fix_gss93subset da Recent GSS93 subset.sav 国xs9ss93,sav G xis_gss93 xls Desktop 的 My Documerts 9 My Computer Fle name: csv_gss93subset.csv Open g Fles of type: All Files(体) Paste My Networlc Places Minimize string widths based on observed values Cancel Then the "Text Import Wizard"dialogue box shows up,which has six steps.Click Next,and in Step 2 of 6,check on the"Yes"radio button to the question"Are variable names included at the top of your file?"because we do have variable names in the first row,and else accept the default settings and keep moving on by clicking Next.Then in Step 6 of6,you will see click Finish. Text Import Wizard-Step 2 of 6 How are your variables arranged? Deimited -Variables are delimited by a specific character (i.e.,comma,tab) Eixed wictth -Variables are aligned in fixed width columns. -Are variable names included at the top of your file? Yes ON№ Text file:D:Documents and SettingsrumimDesktopStatssp1_verybasicSPisp1_verybas 10 200 id,wrkstat,marital,agewed,sibs,childs,age ,1,3,20,3,1,43 ,1,5,0,2,0,44 3,1,3,25,2,0,43 Back Next Finish Cancel Help You should see another SPSS Data Editor window [DataSet2]popping up.As is clear,multiple data files can be simultaneously open in SPSS(we'll mention about this a bit more later). Browse the one you just read in,and let's just close it without saving. 6
Then the “Text Import Wizard” dialogue box shows up, which has six steps. Click Next, and in Step 2 of 6, check on the “Yes” radio button to the question “Are variable names included at the top of your file?” because we do have variable names in the first row, and else accept the default settings and keep moving on by clicking Next. Then in Step 6 of 6, you will see click Finish. You should see another SPSS Data Editor window [DataSet2] popping up. As is clear, multiple data files can be simultaneously open in SPSS (we’ll mention about this a bit more later). Browse the one you just read in, and let’s just close it without saving. 6
Reading Data from Text Files (ASCII fixed format) Finally,let's practice reading the data "fix gss93subset.dat,"which is an ASCII fixed format file. This type of data always comes with a codebook that specifies which column corresponds to which variable.Take a look at this text file (left below;notice there is no variable name header) and its codebook(right below) 113203143 Variable Name Column Number 21502044 313252043 id 1-4 42504045 wrkstat 5 55501078 marital 6 651252283 711222255 agewed 7-8 851243275 sibs 9-10 913221231 childs 11 102501054 age 12-13 Now,unlike the previous examples,there is no easy point-and-click method to read this type of data.What do we do then?The best way is to write syntax commands ourselves to bring in this data.Let's open a new syntax file for this work.From the menu bar at the top,go: File New Stntax You now should be seeing the SPSS Syntax Editor,which is another important window in the SPSS environment (as I emphasized in the introduction,you should eventually learn to use and write the Syntax file for your work.You are now getting a little glimpse of it...).Let's save it as "verybasicspss"in your working directory.Now,let's type the following commands(be sure to specify the file location where you saved the file "fix gss93subset.dat"). data list fixed file='[specify your working directory]lfix_gss93subset.dat' Always end your comment with a period. id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13.- The command DATA LIST is to read a text format data file by assigning names and formats to each variable in the file.The keyword FIXED follows to tell SPSS that our data is a fixed format (actually,this is the SPSS default so you can skip it).The command FILE ="file location/name here"specifies your fixed format file and its location.After the slash(/)we provide SPSS with variable definitions(the variable names and column numbers)from the codebook. Two syntax rules you must remember here: 1.Notice that the whole command ended with a period (".")In SPSS,each command in SPSS must be completed with a period“.”. 2.SPSS Syntax is NOT case-sensitive
Reading Data from Text Files (ASCII fixed format) Finally, let’s practice reading the data “fix_gss93subset.dat,” which is an ASCII fixed format file. This type of data always comes with a codebook that specifies which column corresponds to which variable. Take a look at this text file (left below; notice there is no variable name header) and its codebook (right below). 11320 3143 215 0 2044 31325 2043 425 0 4045 555 0 1078 65125 2283 71122 2255 85124 3275 91322 1231 1025 0 1054 Variable Name Column Number id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13 Now, unlike the previous examples, there is no easy point-and-click method to read this type of data. What do we do then? The best way is to write syntax commands ourselves to bring in this data. Let’s open a new syntax file for this work. From the menu bar at the top, go: File New Stntax You now should be seeing the SPSS Syntax Editor, which is another important window in the SPSS environment (as I emphasized in the introduction, you should eventually learn to use and write the Syntax file for your work. You are now getting a little glimpse of it…). Let’s save it as “verybasicspss” in your working directory. Now, let’s type the following commands (be sure to specify the file location where you saved the file “fix_gss93subset.dat”). data list fixed file='[specify your working directory]\fix_gss93subset.dat' / id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13. Always end your comment with a period. The command DATA LIST is to read a text format data file by assigning names and formats to each variable in the file. The keyword FIXED follows to tell SPSS that our data is a fixed format (actually, this is the SPSS default so you can skip it). The command FILE = “file location/name here” specifies your fixed format file and its location. After the slash (/) we provide SPSS with variable definitions (the variable names and column numbers) from the codebook. Two syntax rules you must remember here: 1. Notice that the whole command ended with a period (“.”). In SPSS, each command in SPSS must be completed with a period “.”. 2. SPSS Syntax is NOT case-sensitive. 7
*verybasicspss.SPS-SPSS Syntax Editor ▣x File Edit View Data Transform Analyze Graphs Utilities Run Add-ons Window Help 公日凸回物◆国昼: % ■层+ Active: DataSet1 data list fixed file='[Specify your working directory]w Run Current fix gss93subset.dat' id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13. Run current command SPSS Processor is ready In 52 Col 1 Now,let's execute our commands.First,highlight them,then to run the highlighted part,hit the Run Current button or alternatively hit Ctrl+R keys.When you run the above command, another Data Editor window should open for this new data.But what did you get there? You should be seeing a blank spreadsheet under the"*Untitled4 []"heading,although from the Variable View it looks like SPSS seems to have variable information.Why aren't we seeing the data itself? To read the data,we need to run another command to actually use this data(because to use this data,SPSS needs to read it!).Get back to your Syntax Editor,and first make sure we are working on this data set. This pull-down menu verybasicspss.SPS-SPSS Syntax Editor indicates your active data source. File Edit View Data Iransform Analyze Graphs Utilities Run Add-ons 卫p 公昌马四。→□兰岳:4色●%■, Active:Unnamed When you have multiple data files open at the same time,you need to tell SPSS which data file you are working on (which is called "Active"file).You can make your file active by simply clicking anywhere in the Data Editor window of the data you want to use(in this case, *Untitled4[),or when you have your Syntax Editor open,you can use the pull-down menu(in this case,it should be set to "Unnamed"since"*Untitled4 []"is neither saved nor named). Once you make sure"*Untitled4 []"is active,type in the following command(don't forget a comma),highlight and run it. list. Now,what do you have in your Data Editor and Output Viewer?You should now be seeing the data content in the Editor,and the command LIST is executed and the result is in the Output Viewer The point is this:SPSS just keeps it in its memory and does not read the data until it needs to, because that's efficient in terms of processing.In this example,SPSS encounters the procedural command LIST,realizes it needs the data"*Untitled4 []"to execute LIST and produce results on that data,and only at that moment does it read in the data. 8
Now, let’s execute our commands. First, highlight them, then to run the highlighted part, hit the Run Current button or alternatively hit Ctrl + R keys. When you run the above command, another Data Editor window should open for this new data. But what did you get there? You should be seeing a blank spreadsheet under the “*Untitled4 []” heading, although from the Variable View it looks like SPSS seems to have variable information. Why aren’t we seeing the data itself? To read the data, we need to run another command to actually use this data (because to use this data, SPSS needs to read it!). Get back to your Syntax Editor, and first make sure we are working on this data set. This pull-down menu indicates your active data source. When you have multiple data files open at the same time, you need to tell SPSS which data file you are working on (which is called “Active” file). You can make your file active by simply clicking anywhere in the Data Editor window of the data you want to use (in this case, “*Untitled4 []”), or when you have your Syntax Editor open, you can use the pull-down menu (in this case, it should be set to “Unnamed” since “*Untitled4 []” is neither saved nor named). Once you make sure “*Untitled4 []” is active, type in the following command (don’t forget a comma), highlight and run it. list. Now, what do you have in your Data Editor and Output Viewer? You should now be seeing the data content in the Editor, and the command LIST is executed and the result is in the Output Viewer. The point is this: SPSS just keeps it in its memory and does not read the data until it needs to, because that’s efficient in terms of processing. In this example, SPSS encounters the procedural command LIST, realizes it needs the data “*Untitled4 []” to execute LIST and produce results on that data, and only at that moment does it read in the data. 8
But suppose you want to explicitly force a data pass so that you can immediately see the read-in data in the Data Viewer.The command EXECUTE does that for you.If you run the following, data list fixed file='[specify your working directory]lfix_gss93subset.dat' id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13. execute. then you would immediately see the result in your Data Editor without running any procedural command.EXECUTE forces all the data to pass(including the data transformation, where you for example create or recode variables and need to read the new data with those new variables so you can use them),but it does nothing else to the session.It just forces a data pass. But as I said,SPSS reads the data as it needs to after all,so in most cases EXECUTE is rarely if ever necessary.In fact,to use EXECUTE at every single data transformation command slows down the processing because SPSS is forced to read the data at every single EXECUTE,even when data reading is unnecessary at that moment.So you should use EXECUTE sparingly.We will be back to this command later and discuss a couple of situations where you absolutely must run EXECUTE. Anyway,let's take a look at our output. *Output1 [Document1]-SPSS Viewer Fle Edt View Data Iransform Insert Format Analyze Graphs Ltities Add-ons We checked“Display commands in log” 色日色B回的中回品屏卧:●后阳增做帝和 in the Options menu,so SPSS displays 日*图Output Read ASCII file (fixed forma the syntax it ran on the output 色L0g data list fixed file='D: 白图List \Documents and Settings\rumim\Desktop\Stat etybasicSP\ap1 verpbasicSP wrkr 一回Title set.dat 高Notes id 1-4 urkatat 5 marital 6 agewed 7-8 siba 9-10 childs 11 age 12-13 自Te对Output Data List vill read 1 records from D: \Documents and Settings\...\sp1_verybasieSp_urkfilelverybasieSp\fix_gss93subset. Variable Rec Start End Format id 4F4.0 5 F1.0 marital 6 F1.0 ageved F2,0 sibs 1 10 F2.0 childs 11 F1.0 age 1 13 F2.0 113t, List marital ageved sibs childs age 20 3 1 43 0 2 0 44 4 SPSS Processor is ready 9
But suppose you want to explicitly force a data pass so that you can immediately see the read-in data in the Data Viewer. The command EXECUTE does that for you. If you run the following, data list fixed file='[specify your working directory]\fix_gss93subset.dat' / id 1-4 wrkstat 5 marital 6 agewed 7-8 sibs 9-10 childs 11 age 12-13. execute. … then you would immediately see the result in your Data Editor without running any procedural command. EXECUTE forces all the data to pass (including the data transformation, where you for example create or recode variables and need to read the new data with those new variables so you can use them), but it does nothing else to the session. It just forces a data pass. But as I said, SPSS reads the data as it needs to after all, so in most cases EXECUTE is rarely if ever necessary. In fact, to use EXECUTE at every single data transformation command slows down the processing because SPSS is forced to read the data at every single EXECUTE, even when data reading is unnecessary at that moment. So you should use EXECUTE sparingly. We will be back to this command later and discuss a couple of situations where you absolutely must run EXECUTE. Anyway, let’s take a look at our output. We checked “Display commands in log” in the Options menu, so SPSS displays the syntax it ran on the output. 9
You see the data content listed.You can save your output by going from the drop-down menu. File Save As... The file extension for the SPSS output is.spv (Note:SPSS older than version 16 has the extension.spo for the output files.To open and view .spo files in SPSS version 16 or later,you need to install SPSS Legacy Viewer.For more information,see the SPSS technical support website).The left-side pane is SPSS's outline view of your output.It serves like a table of content and allows you to navigate different parts of your output by clicking on small output icons. You also see why I strongly recommended you set your "Options"to "Display commands in log."Notice that in the output,you see all the syntax we have run so far printed out,even those you didn't write yourself.This is why I strongly recommended that you set"Display commands in log"in the"Options"menu.First,having the actual commands you run along with the corresponding output helps you greatly with documentation.You can always see what command and options you used to generate the output that you have,and you can always keep track of exactly what you did with the data.This is very important. Further,be aware that SPSS syntax like those is running beneath the point-and-click interface, even when you simply use those pull-down menus without writing syntax commands yourself and do not see the actual commands SPSS runs.As mentioned earlier,you should eventually learn to write commands by using your Syntax Editor yourself and run them from there,instead of pointing and clicking.This is also very important for documentation and reproducibility. Had you written and run the following syntax commands yourself,you would have gotten the same results.They were the syntax running beneath your pointing and clicking Read an Excel file get data /type xls Ifile ='[specify your working directory]lverybasicSPSS\xls_gss93.xls' /sheet name "xls_gss93subset" /readnames on. execute Read a Comma-Separated-Values file get data /type txt /file ='[specify your working directory]IverybasicsPSSIcsv_gss93subset.csv' /firstcase =2 /delimiters="," /variables id f2.0 wrkstat f1.0 marital f1.0 agewed f2.0 sibs f2.0 10
You see the data content listed. You can save your output by going from the drop-down menu. File > Save As… The file extension for the SPSS output is .spv (Note: SPSS older than version 16 has the extension .spo for the output files. To open and view .spo files in SPSS version 16 or later, you need to install SPSS Legacy Viewer. For more information, see the SPSS technical support website). The left-side pane is SPSS’s outline view of your output. It serves like a table of content and allows you to navigate different parts of your output by clicking on small output icons. You also see why I strongly recommended you set your “Options” to “Display commands in log.” Notice that in the output, you see all the syntax we have run so far printed out, even those you didn’t write yourself. This is why I strongly recommended that you set “Display commands in log” in the “Options” menu. First, having the actual commands you run along with the corresponding output helps you greatly with documentation. You can always see what command and options you used to generate the output that you have, and you can always keep track of exactly what you did with the data. This is very important. Further, be aware that SPSS syntax like those is running beneath the point-and-click interface, even when you simply use those pull-down menus without writing syntax commands yourself and do not see the actual commands SPSS runs. As mentioned earlier, you should eventually learn to write commands by using your Syntax Editor yourself and run them from there, instead of pointing and clicking. This is also very important for documentation and reproducibility. Had you written and run the following syntax commands yourself, you would have gotten the same results. They were the syntax running beneath your pointing and clicking. Read an Excel file get data /type = xls /file = ' [specify your working directory]\verybasicSPSS\xls_gss93.xls' /sheet = name "xls_gss93subset" /readnames = on. execute. Read a Comma-Separated-Values file get data /type = txt /file = '[specify your working directory]\verybasicSPSS\csv_gss93subset.csv' /firstcase = 2 /delimiters = "," /variables = id f2.0 wrkstat f1.0 marital f1.0 agewed f2.0 sibs f2.0 10