SPSS Scripting and Automation MARTIN SEBERA FACULTY OF SPORTS STUDIES, MASARYK UNIVERSITY, BRNO SEBERA@FSPS.MUNI.CZ JANUARY 2024 Hello, it is me J Orcid: 0000-0003-3750-1549 Scopus Author ID: 36165218300 ResearcherID: M-9818-2018 Without syntax, SPSS would be just another beautiful GUI without a soul What is scripting and automation? 1.A script is a set of predefined instructions or commands that are executed by the software to perform specific actions. 2.These commands can be saved in a syntax file and executed to perform data manipulation, analysis, and graphical representation tasks automatically. What is scripting and automation? It allows users to: a)Apply the same set of commands to multiple data files. b)Automate complex data transformations and analyses. c)Schedule tasks to run at specific times. d)Reduce the potential for human error in repeated steps. e)Document the analysis process for replication or review. 1. Scripting and motivation - BITCOIN Scripting and motivation - BITCOIN a)the Bitcoin exchange rate in 2022 and b)neural network model that predicts the values of this exchange rate very well i.Neural network si simple. ii.1 input neuron, 8 hidden neurons, 1 hidden bias and 1 "max" output neuron. The inputs are connected to all hidden neurons. All hidden neurons and "hidden bias" are connected to the output neuron "max". BITCON Scripting and motivation - BITCOIN a)Forecasting the price of Bitcoin, like any other cryptocurrency or financial asset, is very complex and involves a number of challenges and uncertainties, external influences and unpredictable moments. b)In retrospect, I could model the development of the course, but the prediction is actually poorly modeled. Well, because I don't have the other input information. Is SPSS a programming language? 1.SPSS Syntax is a command language that is unique to SPSS Statistics. 2.Effectively, it’s the SPSS operating system. 3.The language was developed in the 1960’s and so pre-dates Windows/Mac versions of SPSS by some margin https://static.wixstatic.com/media/65ad94_2630b743e9bd44a6ae33855f7aa00744~mv2.jpg/v1/fill/w_484,h_ 493,al_c,lg_1,q_80,enc_auto/65ad94_2630b743e9bd44a6ae33855f7aa00744~mv2.jpg Why use syntax? 1.Automate your entire analytical process 2.Complete repetitive tasks more quickly 3.Change/fix something to update all your work 4.Share your data preparation and analysis with others 5.A huge range of tasks in IBM SPSS Statistics can be completed using SPSS Syntax 6.SPSS Syntax is a command language that is much easier to understand than many analytical programming languages such as Python or R What is Syntax? 1.SPSS syntax is a programming language that is unique to SPSS. It allows you to write commands that run SPSS procedures, rather than using the graphical user interface. 2.Syntax allows users to perform tasks that would be too tedious or difficult to do using the drop-down menus. This is the case when you are re-running the same analysis many times. 3.Note that the two methods of interacting with SPSS — drop-down menus and syntax — are not mutually exclusive. You can use both methods if you wish, or switch from one method to the other depending on the actions you want to perform. Basic Syntax Rules FORMATTING Statements in SPSS end with a period. SPSS syntax is not case-sensitive. You can use all lower case, all upper case, or a mixture of both when writing syntax. COMMENTS A comment is a line of text in a program that is not read by the computer as a command. In SPSS syntax, placing an asterisk (*) or a forward-slash followed by an asterisk (/*) at the start of a line SPSS Syntax Color Coding By default, SPSS uses color and bolding to indicate the roles of the words in the syntax. Dark blue/purple Procedure names; execution statements Green Statements associated with the given procedure Dark red/orange Option keywords Gray Comments Black Variable names; other text When should I use syntax? The biggest benefits of using SPSS syntax are reproducibility and communication. REPRODUCIBILITY 1.It is far easier to "retrace your steps" with syntax if you need to recall the modifications you've made to your dataset. It's also far easier to find and correct mistakes in your analysis if you have the syntax, as opposed to if you had used the menus. 2.Syntax can easily be modified and re-used on future projects, saving you time and effort in the long run. When should I use syntax? - Communication a)It is much easier to communicate to others what actions you performed in SPSS by showing someone your syntax than it is to describe how you used the menus. b)The content of the menus and dialog windows has changed over time with each version of SPSS, while the syntax has remained relatively unchanged. c)In general, if you are working on a major project (like a thesis, dissertation, or research for publication), or if you are collaborating with others on data analysis, we strongly recommend using SPSS syntax. EXAMPLE sample SPSS script for basic calculations HELP Help > Command Syntax Reference. (This will open a PDF containing the reference manual.) How to Make Syntax Print in the Output Window Click Edit > Options. Click the Viewer tab. Check the box for Display commands in log. Click OK when finished. OPENING THE SYNTAX EDITOR To open a new Syntax Editor window, click File > New > Syntax. Files in SPSS What are the 3 types of files in SPSS? There are three types of SPSS files that we will use during this class: 1.data files, which end in . sav; 2.syntax files, which end in . sps; and 3.output files, which end in . spv. Importing data How the data should look for import? 1.In the first row of column are labels, 2.from second row you have a data Importing Data from an Excel File GET DATA /TYPE=XLSX /FILE='C:\path\to\file.xlsx' /SHEET=name 'Name-of-Sheet' /CELLRANGE=full /READNAMES=on /ASSUMEDSTRWIDTH=32767. EXECUTE. DATASET NAME DataSetExcel WINDOW=FRONT. Note: If you are importing an *.xlsx file, use /TYPE=XLSX. If you are reading an *.xls file, use /TYPE=XLS. The most important lines in this code are /FILE='' and /SHEET=name ''. Importing Data from an Text File(txt, csv) GET DATA /TYPE=XLSX /FILE='C:\path\to\file.xlsx' /SHEET=name 'Name-of-Sheet' /CELLRANGE=full /READNAMES=on /ASSUMEDSTRWIDTH=32767. EXECUTE. DATASET NAME DataSetExcel WINDOW=FRONT. Note: If you are importing an *.xlsx file, use /TYPE=XLSX. If you are reading an *.xls file, use /TYPE=XLS. The most important lines in this code are /FILE='' and /SHEET=name ''. Importing - my experience J 1.Don't leave data import to automatic recognition. 2.Of all statics, the most important thing is the correct data preparation, do it carefully (in SPSS, in Excel, ...) do a standard import. 3.Clear the data… 4.…. Opening the syntax editor To open a new Syntax Editor window, click File > New > Syntax. Syntax editor You can paste the syntax code of every analysis you perform into a syntax editor window by clicking on Paste at the bottom of an analysis dialogue box. Syntax code will be pasted. Syntax editor The left panel of the Syntax Editor window shows an outline of the commands in your syntax, and can be used to navigate within your code. You can jump to a specific part of your code by clicking on the command in the left panel. Syntax editor Syntax can be saved as an *.sps file. How to execute Clicking Run > All will execute the procedure Making sense of SPSS syntax The Dataset Activate command By default, when SPSS Statistics opens a new data file it labels it as ‘DataSet1’. When it opens a second data file, it labels it as ‘DataSet2’ and continues add a sequential number to each new data file that is opened The Frequencies command The syntax for the Frequencies procedure is actually very simple. 1. As with all SPSS syntax procedures it starts with a single Command: FREQUENCIES 2. This is followed by an optional Keyword: VARIABLES 3. It then specifies 3 variables: v100m, Long_jump, Shot_put 4. This is followed by a slash with a Subcommand and another Keyword: /ORDER=ANALYSIS 5. Finally the procedure is completed with a single period character: A few things to note SPSS Syntax is remarkably unfussy about how it’s typed: a)It’s generally not case sensitive b)You can use as many lines as you want to specify a single command. c)It normally doesn’t require correct indentation to run. A few things to note However there are some basic rules: a)Each new command (e.g. Frequencies) must start on a new line. b)Each procedure must end with a period as a ‘command terminator’. c)Most subcommands are separated by slashes (/). The slash before the first subcommand on a command is usually optional Getting help with syntax Notice the useful autocomplete function works when manually typing syntax. Getting help with syntax For instance, if you add a forward slash after a command, a list of subcommands appears. Getting help with syntax A really useful feature is the ability to quickly look-up the syntax diagram for a procedure just by highlighting the command word and clicking the Syntax Help button on the toolbar of an open Syntax window. Examples Remember that you can always create syntax simply by clicking the Paste button in an SPSS dialog • However, in the next few examples we will delve into aspects of syntax that illustrate how different procedures work or reveal functions that aren’t obvious to the casual user • To begin with let’s look at opening data in IBM SPSS Statistics Opening data files The GET FILE command is used to import an SPSS data file (*.sav). • The GET DATA command however is used to import non-native file formats such as Excel workbooks or comma separated (CSV) files. • Note the use of the /TYPE subcommand that specifies the file type to be imported GET DATA /TYPE=XLSX /FILE='D:\Magdeburg\Decathlon.xlsx ' Filtering data with the Select Cases dialog Using the paste button in the Select Cases dialog tends to generate surprisingly complex syntax Useful Syntax Window Functions • Breakpoints: Breakpoints are used to stop command syntax execution at positions so you can check the results at each stage before moving on. • Bookmarks: Creating bookmarks allow you to more easily navigate large command syntax files. • Step Through: You can step through command syntax one command at a time. • Split view: From the main menu click Window > Split View. This splits the syntax editor window into two panes so that you can check one part of the syntax file without losing focus on another. Without syntax, SPSS would be just another beautiful GUI without a soul 25 examples J