ebook img

Programming and Data Management for SPSS Statistics 17.0: A Guide for SPSS Statistics and SAS Users PDF

594 Pages·2016·3.53 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming and Data Management for SPSS Statistics 17.0: A Guide for SPSS Statistics and SAS Users

Programming and Data Management for SPSS® Statistics 17.0 A Guide for SPSS Statistics and SAS® Users Raynald Levesque and SPSS Inc. FormoreinformationaboutSPSSInc.softwareproducts,pleasevisitourWebsiteathttp://www.spss.comorcontact: SPSSInc. 233SouthWackerDrive,11thFloor Chicago,IL60606-6412 Tel: (312)651-3000 Fax: (312)651-3668 SPSSisaregisteredtrademarkandtheotherproductnamesarethetrademarksofSPSSInc. foritsproprietarycomputer software.Nomaterialdescribingsuchsoftwaremaybeproducedordistributedwithoutthewrittenpermissionoftheownersof thetrademarkandlicenserightsinthesoftwareandthecopyrightsinthepublishedmaterials. TheSOFTWAREanddocumentationareprovidedwithRESTRICTEDRIGHTS.Use,duplication,ordisclosurebythe Governmentissubjecttorestrictionsassetforthinsubdivision(c)(1)(ii)ofTheRightsinTechnicalDataandComputerSoftware clauseat52.227-7013.Contractor/manufacturerisSPSSInc.,233SouthWackerDrive,11thFloor,Chicago,IL60606-6412. PatentNo. 7,023,453 Generalnotice:Otherproductnamesmentionedhereinareusedforidentificationpurposesonlyandmaybetrademarksof theirrespectivecompanies. SASisaregisteredtrademarkofSASInstituteInc. PythonisaregisteredtrademarkofthePythonSoftwareFoundation. Microsoft,VisualBasic,VisualStudio,Office,Access,Excel,Word,PowerPoint,andWindowsareeitherregisteredtrademarks ortrademarksofMicrosoftCorporationintheUnitedStatesand/orothercountries. Apple,Mac,andtheMaclogoaretrademarksofAppleComputerInc.,registeredintheU.S.andothercountries. ThisproductusesWinWrapBasic,Copyright1993–2007,PolarEngineeringandConsulting,http://www.winwrap.com. PrintedintheUnitedStatesofAmerica. Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,inanyformorbyany means—electronic,mechanical,photocopying,recording,orotherwise—withoutthepriorwrittenpermissionofthepublisher. Preface Experienceddataanalystsknowthatasuccessfulanalysisormeaningfulreportoften requiresmoreworkinacquiring,merging,andtransformingdatathaninspecifying theanalysisorreportitself. SPSSStatisticscontainspowerfultoolsforaccomplishing andautomatingthesetasks. Whilemuchofthiscapabilityisavailablethroughthe graphicaluserinterface,manyofthemostpowerfulfeaturesareavailableonlythrough commandsyntax—andyoucanmaketheprogrammingfeaturesofitscommandsyntax significantlymorepowerfulbyaddingtheabilitytocombineitwithafull-featured programminglanguage. Thisbookoffersmanyexamplesofthekindsofthingsthat youcanaccomplishusingcommandsyntaxbyitselfandincombinationwithother programming language. For SAS Users IfyouhavemoreexperiencewithSASfordata management, seeChapter32for comparisonsofthedifferentapproachestohandlingvarioustypesofdatamanagement tasks. Quiteoften,thereisnotasimplecommand-for-commandrelationshipbetween thetwoprograms,althougheachaccomplishesthedesiredend. Acknowledgments Thisbook reflects the work of many membersofthe SPSS Inc. staffwho have contributed exampleshere and in DeveloperCentral, aswell asthat ofRaynald Levesque, whose examples formed the backbone of earlier editions and remain importantinthisedition. WealsowishtothankStephanieSchaller,whoprovided manysampleSASjobsandhelpedtodefinewhattheSASuserwouldwanttosee,as wellasMarshaHollarandBrianTeasley,theauthorsoftheoriginalchapter“SPSS StatisticsforSASProgrammers.” iii A Note from Raynald Levesque Ithasbeenapleasuretobeassociatedwiththisprojectfromitsinception. Ihavefor manyyearstriedtohelpSPSSStatisticsusersunderstandandexploititsfullpotential. Inthiscontext,IamthrilledabouttheopportunitiesaffordedbythePythonintegration andinviteeveryonetovisitmysiteatwww.spsstools.netforadditionalexamples. And Iwanttoexpressmygratitudetomyspouse,NicoleTousignant,forhercontinued support and understanding. Raynald Levesque iv Contents 1 Overview 1 UsingThisBook .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 2 DocumentationResources... ... ... ... ... ... ... ... ... ... ... ... ... 3 Part I: Data Management 2 Best Practices and Efficiency Tips 7 WorkingwithCommandSyntax .. ... ... ... ... ... ... ... ... ... ... ... 7 CreatingCommandSyntaxFiles.. ... ... ... ... ... ... ... ... ... ... 7 RunningCommands.. ... ... ... ... ... ... ... ... ... ... ... ... ... 9 SyntaxRules . ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 10 ProtectingtheOriginalData .. ... ... ... ... ... ... ... ... ... ... ... .. 11 DoNotOverwriteOriginalVariables.. ... ... ... ... ... ... ... ... .. 11 UsingTemporaryTransformations ... ... ... ... ... ... ... ... ... .. 12 UsingTemporaryVariables .. ... ... ... ... ... ... ... ... ... ... .. 13 UseEXECUTESparingly .. ... ... ... ... ... ... ... ... ... ... ... ... .. 14 LagFunctions ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 15 Using$CASENUMtoSelectCases... ... ... ... ... ... ... ... ... .. 17 MISSINGVALUESCommand. ... ... ... ... ... ... ... ... ... ... .. 17 WRITEandXSAVECommands... ... ... ... ... ... ... ... ... ... .. 18 UsingComments.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 18 UsingSETSEEDtoReproduceRandomSamplesorValues... ... ... ... .. 19 DivideandConquer .. ... ... ... ... ... ... ... ... ... ... ... ... ... .. 20 UsingINSERTwithaMasterCommandSyntaxFile .. ... ... ... ... .. 20 DefiningGlobalSettings.. ... ... ... ... ... ... ... ... ... ... ... .. 21 v 3 Getting Data into SPSS Statistics 25 GettingDatafromDatabases . ... ... ... ... ... ... ... ... ... ... ... .. 25 InstallingDatabaseDrivers .. ... ... ... ... ... ... ... ... ... ... .. 25 DatabaseWizard. ... ... ... ... ... ... ... ... ... ... ... ... ... .. 27 ReadingaSingleDatabaseTable. ... ... ... ... ... ... ... ... ... .. 27 ReadingMultipleTables.. ... ... ... ... ... ... ... ... ... ... ... .. 29 ReadingSPSSStatisticsDataFileswithSQLStatements . ... ... ... ... .. 32 InstallingtheSPSSStatisticsDataFileDriver ... ... ... ... ... ... .. 34 UsingtheStandaloneDriver . ... ... ... ... ... ... ... ... ... ... .. 34 ReadingExcelFiles... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 35 Readinga“Typical”Worksheet.. ... ... ... ... ... ... ... ... ... .. 36 ReadingMultipleWorksheets ... ... ... ... ... ... ... ... ... ... .. 38 ReadingTextDataFiles... ... ... ... ... ... ... ... ... ... ... ... ... .. 41 SimpleTextDataFiles ... ... ... ... ... ... ... ... ... ... ... ... .. 42 DelimitedTextData .. ... ... ... ... ... ... ... ... ... ... ... ... .. 43 Fixed-WidthTextData ... ... ... ... ... ... ... ... ... ... ... ... .. 47 TextDataFileswithVeryWideRecords.. ... ... ... ... ... ... ... .. 51 ReadingDifferentTypesofTextData. ... ... ... ... ... ... ... ... .. 52 ReadingComplexTextDataFiles.. ... ... ... ... ... ... ... ... ... ... .. 54 MixedFiles .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 54 GroupedFiles ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 55 Nested(Hierarchical)Files .. ... ... ... ... ... ... ... ... ... ... .. 58 RepeatingData .. ... ... ... ... ... ... ... ... ... ... ... ... ... .. 64 ReadingSASDataFiles .. ... ... ... ... ... ... ... ... ... ... ... ... .. 65 ReadingStataDataFiles.. ... ... ... ... ... ... ... ... ... ... ... ... .. 68 CodePageandUnicodeDataSources... ... ... ... ... ... ... ... ... .. 68 4 File Operations 73 UsingMultipleDataSources . ... ... ... ... ... ... ... ... ... ... ... .. 73 vi MergingDataFiles... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 77 MergingFileswiththeSameCasesbutDifferentVariables .. ... ... .. 77 MergingFileswiththeSameVariablesbutDifferentCases .. ... ... .. 81 UpdatingDataFilesbyMergingNewValuesfromTransactionFiles.. .. 85 AggregatingData. ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 87 AggregateSummaryFunctions .. ... ... ... ... ... ... ... ... ... .. 89 WeightingData... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 90 ChangingFileStructure .. ... ... ... ... ... ... ... ... ... ... ... ... .. 92 TransposingCasesandVariables. ... ... ... ... ... ... ... ... ... .. 93 CasestoVariables... ... ... ... ... ... ... ... ... ... ... ... ... .. 94 VariablestoCases... ... ... ... ... ... ... ... ... ... ... ... ... .. 97 5 Variable and File Properties 103 VariableProperties... ... ... ... ... ... ... ... ... ... ... ... ... ... . 103 VariableLabels .. ... ... ... ... ... ... ... ... ... ... ... ... ... . 106 ValueLabels . ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 106 MissingValues .. ... ... ... ... ... ... ... ... ... ... ... ... ... . 107 MeasurementLevel.. ... ... ... ... ... ... ... ... ... ... ... ... . 107 CustomVariableProperties.. ... ... ... ... ... ... ... ... ... ... . 108 UsingVariablePropertiesasTemplates . ... ... ... ... ... ... ... . 110 FileProperties ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 111 6 Data Transformations 113 RecodingCategoricalVariables .. ... ... ... ... ... ... ... ... ... ... . 113 BinningScaleVariables .. ... ... ... ... ... ... ... ... ... ... ... ... . 114 SimpleNumericTransformations . ... ... ... ... ... ... ... ... ... ... . 117 ArithmeticandStatisticalFunctions .. ... ... ... ... ... ... ... ... ... . 118 RandomValueandDistributionFunctions. ... ... ... ... ... ... ... ... . 119 vii StringManipulation .. ... ... ... ... ... ... ... ... ... ... ... ... ... . 120 ChangingtheCaseofStringValues.. ... ... ... ... ... ... ... ... . 121 CombiningStringValues . ... ... ... ... ... ... ... ... ... ... ... . 121 TakingStringsApart . ... ... ... ... ... ... ... ... ... ... ... ... . 122 ChangingDataTypesandStringWidths.. ... ... ... ... ... ... ... ... . 126 WorkingwithDatesandTimes ... ... ... ... ... ... ... ... ... ... ... . 128 DateInputandDisplayFormats.. ... ... ... ... ... ... ... ... ... . 128 DateandTimeFunctions . ... ... ... ... ... ... ... ... ... ... ... . 131 7 Cleaning and Validating Data 137 FindingandDisplayingInvalidValues. ... ... ... ... ... ... ... ... ... . 137 ExcludingInvalidDatafromAnalysis . ... ... ... ... ... ... ... ... ... . 140 FindingandFilteringDuplicates .. ... ... ... ... ... ... ... ... ... ... . 141 DataPreparationOption.. ... ... ... ... ... ... ... ... ... ... ... ... . 144 8 ConditionalProcessing,Looping,andRepeating147 IndentingCommandsinProgrammingStructures. ... ... ... ... ... ... . 147 ConditionalProcessing... ... ... ... ... ... ... ... ... ... ... ... ... . 148 ConditionalTransformations . ... ... ... ... ... ... ... ... ... ... . 148 ConditionalCaseSelection .. ... ... ... ... ... ... ... ... ... ... . 151 SimplifyingRepetitiveTaskswithDOREPEAT . ... ... ... ... ... ... ... . 152 ALLKeywordandErrorHandling. ... ... ... ... ... ... ... ... ... . 155 Vectors... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 155 CreatingVariableswithVECTOR . ... ... ... ... ... ... ... ... ... . 157 DisappearingVectors ... ... ... ... ... ... ... ... ... ... ... ... . 157 LoopStructures .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 159 IndexingClauses. ... ... ... ... ... ... ... ... ... ... ... ... ... . 160 viii NestedLoops ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 160 ConditionalLoops ... ... ... ... ... ... ... ... ... ... ... ... ... . 163 UsingXSAVEinaLooptoBuildaDataFile... ... ... ... ... ... ... . 163 CalculationsAffectedbyLowDefaultMXLOOPSSetting . ... ... ... . 165 9 Exporting Data and Results 169 ExportingDatatoOtherApplicationsandFormats ... ... ... ... ... ... . 169 SavingDatainSASFormat .. ... ... ... ... ... ... ... ... ... ... . 169 SavingDatainStataFormat.. ... ... ... ... ... ... ... ... ... ... . 170 SavingDatainExcelFormat.. ... ... ... ... ... ... ... ... ... ... . 171 WritingDataBacktoaDatabase. ... ... ... ... ... ... ... ... ... . 172 SavingDatainTextFormat... ... ... ... ... ... ... ... ... ... ... . 176 ReadingSPSSStatisticsDataFilesinOtherApplications . ... ... ... ... . 176 InstallingtheSPSSStatisticsDataFileDriver ... ... ... ... ... ... . 177 Example:UsingtheStandaloneDriverwithExcel. ... ... ... ... ... . 177 ExportingResults . ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 179 ExportingOutputtoWord/RTF ... ... ... ... ... ... ... ... ... ... . 180 ExportingOutputtoExcel. ... ... ... ... ... ... ... ... ... ... ... . 183 UsingOutputasInputwithOMS . ... ... ... ... ... ... ... ... ... . 188 AddingGroupPercentileValuestoaDataFile... ... ... ... ... ... . 189 BootstrappingwithOMS . ... ... ... ... ... ... ... ... ... ... ... . 192 TransformingOXMLwithXSLT... ... ... ... ... ... ... ... ... ... . 197 “Pushing”ContentfromanXMLFile . ... ... ... ... ... ... ... ... . 198 “Pulling”ContentfromanXMLFile .. ... ... ... ... ... ... ... ... . 201 PositionalArgumentsversusLocalizedTextAttributes... ... ... ... . 212 LayeredSplit-FileProcessing. ... ... ... ... ... ... ... ... ... ... . 213 ControllingandSavingOutputFiles... ... ... ... ... ... ... ... ... ... . 214 ix 10 Scoring Data with Predictive Models 217 Introduction .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 217 BasicsofScoringData... ... ... ... ... ... ... ... ... ... ... ... ... . 218 TransformingYourData.. ... ... ... ... ... ... ... ... ... ... ... . 218 MergingTransformationsandModelSpecifications . ... ... ... ... . 219 CommandSyntaxforScoring. ... ... ... ... ... ... ... ... ... ... . 219 MappingModelVariablestoSPSSStatisticsVariables .. ... ... ... . 221 MissingValuesinScoring ... ... ... ... ... ... ... ... ... ... ... . 221 UsingPredictiveModelingtoIdentifyPotentialCustomers... ... ... ... . 222 BuildingandSavingPredictiveModels .. ... ... ... ... ... ... ... . 222 CommandsforScoringYourData. ... ... ... ... ... ... ... ... ... . 230 IncludingPost-ScoringTransformations . ... ... ... ... ... ... ... . 232 GettingDataandSavingResults . ... ... ... ... ... ... ... ... ... . 232 RunningYourScoringJobUsingtheSPSSStatisticsBatchFacility .. . 234 Part II: Programming with Python 11 Introduction 237 12 Getting Started with Python Programming in SPSS Statistics 241 ThespssPythonModule.. ... ... ... ... ... ... ... ... ... ... ... ... . 241 RunningYourCodefromaPythonIDE ... ... ... ... ... ... ... ... . 243 TheSpssClientPythonModule... ... ... ... ... ... ... ... ... ... ... . 245 SubmittingCommandstoSPSSStatistics. ... ... ... ... ... ... ... ... . 249 DynamicallyCreatingCommandSyntax .. ... ... ... ... ... ... ... ... . 251 x

Description:
2007. SPSS Inc., — 594 p.Experienced data analysts know that a successful analysis or meaningful report often requires more work in acquiring, merging, and transforming data than in specifying the analysis or report itself. SPSS Statistics contains powerful tools for accomplishing and automating t
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.