• No results found

Quantum Vol1

N/A
N/A
Protected

Academic year: 2021

Share "Quantum Vol1"

Copied!
274
0
0

Loading.... (view fulltext now)

Full text

(1)

Volume 1 Data Editing

(2)

All rights reserved as an unpublished work, and the existence of this notice shall not be construed as an admission or presumption that publication has occurred. No part of the materials may be used, reproduced, disclosed or transmitted to others in any form or by any means except under license by SPSS Ltd. or its authorized distributors. SPSS Limited Maygrove House 67 Maygrove Road LONDON NW6 2EG England

Please address any comments or queries about this manual to the Support Department at the above address, or via e-mail to: [email protected]

(3)

About this guide ... vii

1 Introduction...1

1.1 What Quantum does ...1

1.2 Stages in a Quantum run ...2

2 Your Quantum program...3

2.1 Storing your program on the computer ...3

2.2 Components of a program ...3

Edit statement ...4

Checking and verification statements ...4

Dealing with errors in your data ...5

Loops and routing ...5

Tabulation statements ...5

3 Writing in the Quantum language...7

3.1 The character set ...7

3.2 Formatting your program ...8

3.3 Comments ...9

3.4 Continuation ...9

3.5 Dealing with possible syntax errors ...10

3.6 Printing error messages on the screen ...11

4 Basic elements...13

4.1 Data constants ...13

Individual constants ...13

Strings of data constants ...15

4.2 Numbers ...16

Whole numbers ...16

Real numbers ...16

4.3 Variables and arrays ...17

Data variables ...18

Integer variables ...20

Real variables ...21

Reading real numbers from columns ...23

4.4 Subscription ...23

5 Expressions...25

5.1 Arithmetic expressions ...25

Combining arithmetic expressions ...26

Counting the number of codes in a column ...28

Generating a random number ...29

5.2 Logical expressions ...30

Comparing values ...30

Comparing data variables and data constants ...31

(4)

Comparing variables and arithmetic expressions to a list ... 42

5.3 Speeding up large programs ... 45

6 How Quantum reads data... 47

6.1 Types of record ... 47

Ordinary records ... 47

Multicard records ... 47

Multicard records with trailer cards ... 48

6.2 Reading data into the C array ... 48

Ordinary records ... 48

Multicard records ... 49

Ignoring card types ... 49

6.3 Processing the data ... 49

6.4 Trailer cards ... 50

thisread ... 50

allread ... 50

firstread and lastread ... 51

Examples ... 51

6.5 Columns 1 to 100 ... 52

6.6 Reserved variables ... 52

6.7 Using spare columns ... 52

6.8 Describing the data structure ... 53

Record type ... 53

Record length ... 54

Serial number location ... 55

Card type location ... 55

Required card types ... 56

Repeated card types ... 56

Highest card type number ... 57

Dealing with alphanumeric card types ... 58

Merge sequence for trailer cards ... 58

6.9 Merging data files ... 59

Merging complete cards ... 59

Merging a field of data from an external file ... 61

6.10 Multicard records of more than 100 columns per card ... 63

6.11 Reading non-standard data files ... 63

7 Writing out data... 65

7.1 Print files ... 65

Printing out individual records ... 65

Writing out parts of records ... 68

7.2 Data files ... 69

Creating new cards ... 70

7.3 Writing to a report file ... 70

Data variables ... 71

Integer variables ... 74

Real variables ... 75

Text and white space ... 76

(5)

7.4 Defining the file type ... 78

7.5 Default print parameters for write statements ... 81

7.6 Writing out data in a user-defined format ... 84

8 Changing the contents of a variable... 89

8.1 Assignment statements ... 89

Copying codes ... 90

Partial column replacement ... 92

Storing arithmetic values ... 95

Assignment with and, or and xor ... 99

8.2 Adding codes into a column ... 102

8.3 Deleting codes from a column ... 103

8.4 Forcing single-coded answers ... 104

8.5 Setting a random code in a column ... 107

8.6 Reading numeric codes into an array ... 108

8.7 Clearing variables ... 111

8.8 Checking array boundaries in assignment statements ... 112

8.9 Assigning values to T variables in the data file ... 113

9 Flow control... 115

9.1 Statements of condition – if ... 115

9.2 Statements of condition – else ... 117

9.3 Routing around statements ... 118

9.4 continue ... 119

9.5 Loops ... 119

do with individually specified numeric values ... 120

do with numeric ranges ... 121

do with codes ... 122

Nested loops ... 123

Routing with loops ... 124

9.6 Rejecting records ... 124

9.7 Jumping to the tabulation section ... 126

9.8 Stopping the processing of data by the edit ... 127

9.9 Canceling the run ... 128

9.10 Going temporarily to the tab section ... 129

10 Examining records... 133

10.1 Holecounts ... 133

Creating a holecount ... 135

Filtered holecounts ... 136

Counting trailer cards ... 136

Multiplied holecounts ... 136

10.2 Frequency distributions ... 138

Creating a frequency distribution ... 139

Multiplied frequency distributions ... 142

11 Data validation... 143

(6)

The action code ... 145

Checking type of coding ... 146

Comments with require ... 147

Checking codes in columns ... 148

Exclusive codes ... 150

Automatic error correction ... 151

Defaults in a require statement ... 152

11.3 Validating logical expressions ... 153

11.4 Testing the equivalence of logical expressions ... 154

11.5 Actions when a require statement fails ... 156

11.6 Combining testing sentences ... 157

12 Data correction... 159

12.1 Forced editing (forced cleaning) ... 159

12.2 On-line data correction ... 160

12.3 On-line editing commands ... 162

Displaying columns in the record ... 162

Correcting records ... 163

Accepting and rejecting records ... 165

Creating and deleting cards ... 166

Record editing commands ... 166

Canceling the online edit ... 167

Redefining on-line edit command names ... 167

12.4 Creating clean and dirty data files ... 167

12.5 Correcting data from a corrections file ... 170

12.6 Missing values in numeric fields ... 172

Facilities provided by missing values processing ... 172

Switching missing values processing on and off ... 172

Missing values in arithmetic expressions and assignments ... 173

Manual assignment of the missing value to a variable ... 174

Testing whether a variable has the value missing_ ... 175

13 Using subroutines in the edit... 177

13.1 Calling up subroutines ... 177

13.2 Subroutines in the Quantum library ... 178

Using look-up files ... 178

Converting multicoded data to single-coded data ... 181

13.3 Writing your own routines ... 182

Writing subroutines in C ... 182

Writing subroutines in Quantum ... 185

13.4 Calling functions from C libraries ... 192

14 Creating new variables... 195

14.1 Naming variables ... 195

14.2 Defining variables ... 196

14.3 The default variables file ... 198

(7)

15 Data-mapped variables... 201

15.1 Advantages of data-mapping files ... 201

15.2 Contents of a data-mapping file ... 203

15.3 Defining data-mapped variables ... 203

15.4 Using data-mapped variables ... 204

15.5 Assigning values to data-mapped variables ... 207

15.6 Testing the value of a data-mapped variable ... 211

Test the numeric value ... 211

Test the categoric response ... 212

15.7 Using data-mapped variables in analysis specifications ... 213

15.8 Using parameter substitution with data-mapped variables ... 215

15.9 Additional features using data-mapped variables ... 216

15.10 Automatically generating a Quantum spec ... 217

Quancept CAPI and Quancept Web text-formatting options ... 218

Reducing the response texts ... 219

Files produced by qdiaxes ... 220

16 Running Quantum under Unix and DOS... 223

16.1 Which version to use ... 223

16.2 The Quantum command ... 224

Compressed and non-standard data files ... 225

16.3 Compiling your program file ... 226

16.4 Loading the C code ... 227

16.5 Reading the data ... 228

16.6 Weighting, accumulation and manipulation ... 229

16.7 Creating tables ... 229

16.8 Log files and running in the background ... 230

16.9 Running more than one job in a directory ... 231

16.10 The Quantum temporary directory ... 231

16.11 The Quantum permanent directory ... 232

(8)
(9)

The Quantum User’s Guide is written primarily for Quantum spec writers. It is also a useful reference for Quanvert database administrators and others who prepare data for use with Quanvert or Quanvert Text.

This guide is not intended as a tutorial or teach-yourself document. Instead, it provides a complete and detailed description of the Quantum language and the Quantum programs. However, the guide has been designed with your needs in mind. If you are an experienced user, you will find the Quick Reference boxes at the start of each section helpful as a reminder of syntax. If you are less experienced, you will probably prefer the more detailed explanations and examples in the main body of each section.

The Quantum User’s Guide is divided into four volumes, which are described in more detail below. All the volumes contain a comprehensive index that covers all four volumes.

Volume 1, Data editing

Volume 1 of the Quantum User’s Guide covers data editing, validation and cleaning:

• Chapters 1 to 3 give you an overview of the language and explain the basic concepts of Quantum spec writing.

• Chapter 4, ‘Basic Elements’, describes constants, numbers and variables. • Chapter 5, ‘Expressions’, describes arithmetic and logical expressions.

• Chapter 6, ‘How Quantum reads data’, describes types of records, data structure, trailer cards, reserved variables, merging data files and reading non-standard data files.

• Chapter 7, ‘Writing out data’, describes creating a new data file, copying records to a print file, and writing to a report file.

• Chapter 8, ‘Changing the contents of a variable’, describes the Quantum assignment statements, adding and deleting codes in a column, forcing single-coded answers, setting a random code in a column, reading numeric codes into an array and clearing variables.

Chapter 9, ‘Flow control’, describes the if and else statements, routing around statements, loops, rejecting records, jumping to the tabulation section and canceling the run.

• Chapter 10, ‘Examining records’, describes holecounts and frequency distributions.

(10)

• Chapter 12, ‘Data correction’, describes forced cleaning, on-line data correction, creating clean and dirty data files, correcting data from a corrections file, and missing values in numeric fields.

• Chapter 13, ‘Using subroutines in the edit’, describes how to call up subroutines, the subroutines in the Quantum library, writing your own subroutines and calling functions from C libraries.

• Chapter 14, ‘Creating new variables’, describes how to name and define variables in your Quantum spec.

• Chapter 15, ‘Data-mapped variables’, describes the data-mapped variables feature.

• Chapter 16, ‘Running Quantum under Unix and DOS’, describes how to compile and run your Quantum program.

Volume 2, Basic tables

Volume 2 of the Quantum User’s Guide covers axes and creating basic tables:

• Chapter 1, ‘Introduction to the tabulation section’, provides an introduction to creating tables in Quantum.

• Chapter 2, ‘The hierarchy of the tabulation section’, describes the components of a tabulation program, the hierarchies of Quantum, how to define run conditions, the options that are available on the a, sectbeg, flt and tab statements, the default options file and some sample tables.

• Chapter 3, ‘Introduction to axes’, describes how to create an axis, the types of elements within an axis, how to define conditions for an element, the n count creating elements, subheadings, netting and axes within axes.

Chapter 4, ‘More about axes’, describes the col, val, fld and bit statements, filtering within an axis, and options on axis elements.

• Chapter 5, ‘Statistical functions and totals’, describes totals, averages, means, the standard deviation, standard error and error variance statements and how to create percentiles.

• Chapter 6, ‘Using axes as columns’, describes special considerations for when axes are used for the columns of a table.

Chapter 7, ‘Creating tables’, describes the syntax of the tab statement, multidimensional tables, multilingual surveys, combining tables, printing more than one table per page, and suppressing percentages and statistics with small bases.

(11)

• Chapter 8, ‘Table texts’, describes table titles, underlining titles, printing text at the foot of a page, table and page numbers and controlling table justification.

• Chapter 9, ‘Filtering groups of tables’, describes general filter statements, named filters and nested filter sections.

• Chapter 10, ‘Include and substitution’, describes filing and retrieving statements, symbolic parameters and grid tables.

• Chapter 11, ‘A sample Quantum job’, provides an example of a Quantum specification and the tables it produces.

• Appendix A, ‘Limits’, describes the limits built into Quantum.

• Appendix B, ‘Error messages’, contains a list of compilation error messages with suggestions as to why you may see them and how to solve the problems which caused them to appear. • Appendix C, ‘Options in the tabulation section’, provides a summary of the options available

in the tabulation section.

Volume 3, Advanced tables

Volume 3 of the Quantum User’s Guide covers advanced tables and statistics:

• Chapter 1, ‘Weighting’, describes the weighting methods that you can use in Quantum. • Chapter 2, ‘Row and table manipulation’, describes how to create new rows and tables using

previously created tables or parts of previously created tables.

• Chapter 3, ‘Dealing with hierarchical data’, describes how to use analysis levels in Quantum. • Chapter 4, ‘Descriptive statistics’, describes the axis-level and table-level statistical tests that

are available in Quantum and provides details of the chi-squared tests, non-parametric tests on frequencies and Friedman’s two-way analysis of variance.

• Chapter 5, ‘Z, T and F tests’, describe the Z, T and F tests that are available in Quantum. • Chapter 6, ‘Other tabulation facilities’, describes how to include C code and edit statements in

the tabulation section and how to sort tables.

• Chapter 7, ‘Special T Statistics’, describes the special T statistics that are available in Quantum.

(12)

• Chapter 9, ‘Laser printed tables with PostScript’, describes how to convert the standard tabulation output into a file suitable for printing on a PostScript laser printer.

• Appendix A, ‘Options in the tabulation section’, provides a summary of the options available in the tabulation section.

Volume 4, Administrative functions

Volume 4 of the Quantum User’s Guide covers administrative functions:

• Chapter 1, ‘Files used by Quantum’, describes files you may need to create in order to use certain Quantum facilities, including the variables file, the levels file, the default options file, the run definitions file, the merges file, the corrections file, the rim weighting parameters file, and the C subroutine code file, aliases for Quantum statements, customized texts, and user-definable limits.

• Chapter 2, ‘Files created by Quantum’, describes many of the files created during a run and draws your attention to those of particular interest.

• Chapter 3, ‘Quantum Utilities’, describes how to tidy up after a Quantum run and how to check column and code usage.

• Chapter 4, ‘Data conversion programs’, describes the q2cda and qv2cda programs that convert tables into comma-delimited ASCII format, the qtspss and nqtspss programs that convert Quantum data into SPSS format, and the qtsas and nqtsas programs that convert Quantum data into SAS format.

• Chapter 5, ‘Preparing a study for Quanvert’, describes the tasks you need to perform before converting a Quantum spec and data file into a Quanvert database.

• Chapter 6, ‘Files for Quanvert users’, describes files that are specific to either Quanvert Text or Windows-based Quanvert.

• Chapter 7, ‘Creating and maintaining Quanvert databases’, describes how to create and maintain Quanvert databases.

• Chapter 8, ‘Transferring databases between machines’, describes how to transfer databases between machines and the programs provided to help you achieve this.

• Appendix A, ‘Limits’, lists limits built into Quantum.

• Appendix B, ‘Error messages’, contains a list of compilation error messages with suggestions as to why you may see them and how to solve the problems that cause them to appear. • Appendix C, ‘Quantum data format’, describes the Quantum data format.

(13)

• Appendix D, ‘Using the extended ASCII character set’, explains how you can use Quantum with data that contains characters in the extended ASCII character set.

• Appendix E, ‘ASCII to punch code conversion table’, provides a table showing ASCII to punch code conversions.

• Appendix F, ‘Will this job run on my machine’, offers suggestions on how you can check whether a particularly large job will run on your computer.

Symbols and typographical conventions

Words which are keywords in the Quantum language are normally printed in italics in the text. In the main description of each keyword, the keyword is shown in bold the first time it is mentioned. When showing the syntax of a statement, as in the Quick Reference sections, all keywords are printed in bold. Parameters, such as question texts or responses, whose values are user-defined are shown in italics. Optional parameters are enclosed in square brackets, that is, [ ].

All examples are shown in fixed width type.

The ✎ symbol marks a note or other point of particular interest.

The ☞ symbol marks a reference for further reading related to the current topic.

Comments

SPSS MR welcomes any comments you may have about this guide, and any suggestions for ways in which it could be improved.

(14)
(15)

Quantum is a highly sophisticated and very flexible computer language designed to simplify the process of obtaining useful information from a set of questionnaires.

Quantum has been designed with market researchers in mind so its syntax and grammar are similar to English. Nevertheless, it is still a computer language and as such should be used with precision and understanding.

The four volumes of the Quantum User’s Guide have three basic functions: • To explain the Quantum language.

• To provide you with enough information about how Quantum works to enable you to carry out a specific task.

• To help you work out what went wrong when errors occur or when your output is not what you expected.

1.1 What Quantum does

Quantum is a very flexible language which performs a variety of tasks. It can: • Check and validate your data.

• Edit and correct your data.

• Produce different types of lists and reports of data. • Produce new data files.

• Recode data and produce new variables.

• Generate tables (in different languages, provided that the translated texts exist). • Perform statistical calculations.

Any Quantum run may perform as many or as few of these tasks as you like, but for each run the basic format is the same.

(16)

1.2 Stages in a Quantum run

First, the data is read onto a disk. Data on disk can come from a number of different sources, for example:

• It may be entered directly via a terminal by a telephone interviewer using Quancept CATI. • It may be collected over the World Wide Web using software such as Quancept Web.

• It may be entered directly into a computer by an interviewer conducting a personal interview using Quancept CAPI.

• It may be entered by a data entry clerk using a data entry package. Next, the tasks to be performed are defined using the Quantum language.

Then, Quantum translates these tasks into instructions that the computer can understand. Finally, the computer itself uses this program to run your job.

Quantum comprises two sections — an edit section and a tabulation section. The edit section checks and validates the data, generates lists and reports, corrects data, produces new data files, and recodes data and creates new variables. The tabulation section produces tables and performs statistical calculations.

Quantum reads the records in the data file one at a time and passes them through the various parts of the Quantum program. As long as there are records remaining in the data file, the loop of ‘read a record −> edit −> tabulate’ is repeated; once the last record has been processed, the tables are ready for printing.

If errors occur at any point in a Quantum run an error message is printed telling you what is wrong.

For details of the error messages that can occur, see appendix B, ‘Error messages’ in the Quantum User’s Guide Volume 2.

(17)

Your Quantum program is the basic requirement for any Quantum run. It tells the computer what tasks it has to perform. All Quantum programs are written in the Quantum language which both you and the computer can understand. When writing in this language you must take care that you say exactly what you mean; otherwise your output may not be quite what you expect. The computer cannot guess at what you mean it to do; it only does what you tell it.

2.1 Storing your program on the computer

All Quantum programs are stored in separate files on the computer. Each file has a unique name which may be made up of any characters on your keyboard, but you are advised to use only letters and numbers in your filenames.

A typical program might look like this: *include edit

a;dsp;spechar=–*;decp=0;flush *include tabs

*include axes

where the file called edit contains editing instructions, the file called tabs contains statements defining the tables required, and axes contains statements which define the individual rows and columns each table is to have. The a; statement lists characteristics that all tables are to have, although some of these characteristics can be overridden for individual tables or individual table elements.

2.2 Components of a program

A Quantum program is made up of a series of statements defining the actions to be taken. If you are typing Quantum programs on your screen you will notice that statements of more than 80 characters wrap around onto the next line and appear to be on two lines in the file. As long as these statements have 200 characters or fewer, Quantum can read them, but you may prefer to make the lines shorter for ease of reading on your screen.

(18)

Edit statement

Quantum edit statements contain a Quantum keyword and other texts and numbers. Statements in the edit section can generally start in any column, although comments and continuation characters must start in column 1. A line may contain one or more statements, as long as each statement is separated by a semicolon.

Edit statements may be preceded by a label number of up to five digits allowing them to be referenced by other parts of the program, for example:

total = c56 + c57 + c58 if (total.gt.8) go to 100 require sp c(66,70)

100 write

Here we are adding the number in column 56 to those in columns 57 and 58 and saving the result in a variable called ‘total’. If this value is greater than eight we go to statement 100, otherwise we continue with the statement immediately after the if line.

Checking and verification statements

Quantum offers you the ability to check and verify your data prior to tabulation. Suppose your questionnaire contains a series of questions to be answered only by people buying a specific brand of tea. You may want to check that everyone who didn’t buy tea has a blank in all columns related to tea. On the other hand, if they did buy a specific brand of tea, you could check whether the codes in the following columns were within a specific range.

The statement that you would use for this type of test is require. To perform the test given as an example, we might write:

if (c24’1’) r nb c(25,30); else; r b c(25,30)

This says that if column 24 contains a ‘1’, then columns 25 to 30 must not be blank, otherwise, if column 24 does not contain a ‘1’, then columns 25 to 30 must all be blank.

More generalized checking facilities exist which enable you to produce frequency distributions of numeric data (e.g., how many respondents have the number 201 in columns 13 to 15) or holecounts (marginals) which show the broad pattern of coding across all columns in the data. Words associated with these are list and count.

(19)

Dealing with errors in your data

When errors are found in the data, you have several courses of action open to you. You may: • Write out incorrect records for further investigation (write or require).

Copy the record to a different file (split or write).

• Correct the errors (Quantum statements, online edit, file of corrections). For example, we may write:

if (c224’5’) write

to write out all records in which column 24 of card 2 contains a 5. The records are written to the default print file, out2

Incidentally, many of the statements mentioned in this section may be used for other purposes, rather than just to deal with errors.

Loops and routing

Quantum offers you many aids to efficient programming. Repetitive checks may be specified once with instructions to Quantum to repeat them a given number of times or until a certain condition is satisfied. The word associated with loops of this kind is do.

There are two sorts of routing: you may either go to another edit statement (go to) or you may send the record straight on to the tabulation section (return).

Tabulation statements

Tabulation statements tell Quantum which tables are required and how to create them. They consist of a start letter or keyword to identify the type, and may be followed by other keywords, numbers or text. They are used to define rows and columns (elements), the variables that are to be cross-tabulated (axes) and finally, the tables themselves.

There are also statements for weighting your data and for creating tables by manipulating the contents of tables created previously in the current run or even in other runs.

(20)
(21)

Writing in the Quantum language is very easy but as with all computer languages it needs to be done with care and precision to obtain the required results.

3.1 The character set

The characters and symbols that you may use in Quantum are: • The 26 uppercase letters A to Z

• The 26 lowercase letters a to z • The 10 digits 0 to 9

• The space (blank) character

• The special symbols + – / * . , ; : ’ $ = & ( ) { } ! | > # @ % Some of these symbols have special meanings:

+ Addition sign or continuation of a long statement – Subtraction sign or the 11-punch

/ Slash sign for division, or an abbreviation for ‘through’ (i.e., 1/9 is 1 to 9 inclusive) * Asterisk for multiplication

, Comma for separating column numbers in field specifications ; Semicolon for separating statements on the same line

: Colon for specifying ranges

’ Single quotes for single codes (always used in pairs) $ Dollar signs for fields of codes (always used in pairs) = Equal sign for assignments

& Ampersand (12) punch or end of g statement ( ) Parentheses to enclose field specifications { } Braces to enclose vectors (i.e., lists of numbers) ! Exclamation mark for splitting long words

| Vertical bar to split words or create vertical lines in tables # Hash (pound) sign for identifying rows/tables for manipulation @ ‘At’ sign for identifying rows/tables for manipulation

(22)

Where symbols have two meanings, the meaning required will become clear in the context in which the symbol is employed.

3.2 Formatting your program

Quantum is a ‘free-format’ language which means that within reason you may enter your program however you like. Statements occupy columns 1 to 200 of successive lines and may be written in uppercase or lowercase or a combination. Thus:

IF (C132’1’) WRITE; REJECT is exactly the same as:

if (c132’1’) write; reject

The exception to this is text in tables, where the text is printed on the tables in the same case as you write it in your Quantum program. Additionally, you must set up table text so that it fits on the paper when you print your tables. Therefore, if you want the table title to be printed on two lines, you must write it on two lines in your program.

Generally, spaces are allowed anywhere in a Quantum program except within Quantum keywords. Blank lines in a program are ignored.

As we mentioned earlier, Quantum has separate edit and tabulation sections which may or may not be in the same file. If your program contains an edit, it must precede the tabulation statements and must be enclosed by the words ed and end, each on a separate line, thus:

ed .

edit statements

. end

Errors will occur if either of these words is missing. If there is no edit, these statements are not needed.

(23)

3.3 Comments

Comment statements insert comments or information into the Quantum program. They do not affect the way your program works because they are ignored when the program is run to produce tables.

Comments are identified either by a capital C in column 1 or by a slash and an asterisk in columns 1 and 2 respectively (/*). If a comment needs more than one line, each line must start with the appropriate notation otherwise it will be assumed to require some sort of action.

/* This is the first comment /* This is the second comment

It is a good idea to put comment statements in your program in case someone else has to take over your job or alternatively to remind yourself what you are doing and why. For example:

/* Edam is 1 if Edam mentioned at Q1, Q3 or Q6 if (c110’1’.or.c114’1’.or.c121’1’) edam=1

3.4 Continuation

Any Quantum statement may be continued over several lines by starting the second and subsequent lines with + or ++, depending on where the statement is split.

A single plus sign is used when the statement is split between keywords. This assumes that a semicolon appears at the end of each continued line, whether or not there is actually one there. Take the statement:

if (c132’12’.and.t5.gt.50) write $t5 incorrect$; else; write ofil This could be split in three places with a single plus sign for a continuation:

if (c132’12’.and.t5.gt.50) +write $t5 incorrect$ +else

+write ofil

We have omitted the semicolons at the end of each line, but it would not be wrong to leave them in. The double-plus sign introduces an internal continuation of a long statement over several lines. Statements may be split between lexics; that is, between keywords, conditions, lists of numbers, and so on, but not in the middle of any of these. In our previous example, we could write:

(24)

A double plus is needed here because we have split an expression in which one parameter is dependent on the other. The statement on the first line means nothing on its own, neither does the second line, hence the ++. We could equally well have split the expression before the .and. or before or after the .gt.. To split it between t and 5, or in any other similar place, is incorrect because the two characters by themselves do not mean anything.

There is no limit to the number of consecutive continuations of either type.

3.5 Dealing with possible syntax errors

Quick Reference

To have possible syntax errors (that is, ones which Quantum can process even though they are not quite perfect) treated as fatal, type:

check_

at the start of the edit.

To have possible syntax errors flagged but ignored, type:

nocheck_

at the start of the edit. This is the default.

When the Quantum compiler is checking your program and finds an error it flags the incorrect statement with an explanatory error message and continues with the next statement. If any of these errors are fatal — that is, Quantum cannot convert your statement into C code — the run will be terminated.

Sometimes Quantum finds statements which are not quite correct, but which it can still convert into C. In these cases the compiler flags the statement with the message ‘Possible syntax error’ and continues as if nothing were wrong. You can choose to have this type of error treated as fatal and have the run terminated at the end of the compilation by entering the statement check_ (note the underscore at the end) at the start of your edit.

The statement nocheck_ causes possible syntax errors to be flagged but ignored, and this is the default.

(25)

3.6 Printing error messages on the screen

Quick Reference

To have more or less than the default of 20 error messages displayed on your screen, type:

errprint n

before the edit and tabulation sections. Where n is the number of messages you wish to see.

When the Quantum compiler finds errors in your program, it copies them to the compilation listing file. It also displays the first twenty messages on your screen. You may increase or decrease this number by placing the statement:

errprint n

at the top of your main program file, before the edit and tabulation sections.

n is the number of messages you want to see on your screen: it must be an integer. Thus:

errprint 5

prints the first five error messages on the screen and in the listing file, and then any others only in the file.

(26)
(27)

There are three basic elements in Quantum: • Data constants.

• Integer numbers. • Real numbers.

which are stored in variables:

4.1 Data constants

Individual constants

Quick Reference

To refer to one or more codes in a single column, type:

’codes’

An individual constant is one or more of the codes 1234567890–& or blank. The – is sometimes referred to as the 11 or X punch, and & is sometimes called the 12, V or Y punch. Each code represents one answer to a question. For example, let’s take the question ‘What is your favorite color?’ which has the response list:

coded into one column. If my favorite color is green, this will appear in the data file as a 4 in the appropriate column, just as if your favorite color is red, there will be a 1 in that column.

Data variables store data constants Integer variables store whole numbers Real variables store real numbers

Red 1 Yellow 2 Blue 3 Green 4 Black 5 White 6

(28)

To refer to these answers inside your Quantum program (maybe we only want our table to include those respondents whose favorite color is blue), type in the code enclosed in single quotes: ’3’

You will also have to tell Quantum which column to look in.

To find out how to refer to columns, see ‘Data variables’ later in this chapter.

Several codes may be combined in the same column and are called multicodes. Throughout this manual when we talk of multicodes or multicoding we mean two or more codes in the same column. Suppose the next question asks me to choose three colors from the same list; I pick yellow, black and white. If these answers were all coded in the same column (a multicoded column), we would refer to them by typing:

’256’ or ’526’ or ’652’

or any other variation of those three codes. Quantum does not care what order you enter the codes in.

If you have a series of consecutive codes in the order &–01234567890–&, you may either type each code separately or you may enter the first and last codes separated by a slash (/) meaning ‘through’, as shown below:

As you can see, the last two examples mean exactly the same thing. However, the notations ’0/&’ and ’0–&’ are not the same: ’0/&’ means ’01234567890–&’ whereas ’0–&’ is ’0’, ’–’ and ’&’ only.

Some combinations of codes represent ASCII characters; that is, they represent characters which you can type on your screen:

The only time you would use letters rather than codes (that is, ‘A’ rather than ‘&1’) is when the questionnaire tells you that a column should contain a letter.

’1/7’ means ’1234567’

’&/4’ means ’&–01234’

’&/9’ means ’&–0123456789’ (all 12 codes) ’1/&’ means ’1234567890–&’ (all 12 codes)

’&1’ is the equivalent of ’A’ ’&2’ is the equivalent of ’B’

(29)

For further information, see appendix E, ‘ASCII to punch code conversion table’ in the Quantum User’s Guide Volume 4.

Sometimes we may need to write a notation for ‘no codes’ — for instance, if my favorite color does not appear in the list of choices. To do this, we write ’ ’ (that is, a blank enclosed in single quotes).

The notation ’ ’ is a special case since blank is not really a code. If you type a blank inside single quotes with any other characters Quantum will follow its usual rule of ignoring spaces. This means that references of the form ’ 12 ’ are read as ’12’.

Strings of data constants

Quick Reference

To refer to a string of codes in a field of columns, type:

$codes$

The list of codes contains one code per column.

When data constants are single-coded or the multicodes correspond to ASCII characters (for example, ‘A’, ‘B’) they may be strung together. Strings of data constants are sometimes called literals or column fields. Strings are enclosed in dollar signs, with the component single codes losing their single quotes. For example:

$12345$ $ABC$ $916 7&$

The first string is five columns long with 1 in the first column, 2 in the second, 3 in the third, and so on. The third string is six columns wide with the fourth column being blank.

Times when you might use strings are:

• When you want to refer to a questionnaire serial number.

• When the answers to a question are represented by codes of more than 1 digit. For example, in a car ownership survey the car make and model owned may be represented by a 3-digit code. To pick up respondents owning a particular type of car you would need to check whether the relevant columns contained the code for that car. For instance, to look for owners of Ford Escorts you might ask Quantum to search for the string $132$ in a particular field of columns.

(30)

4.2 Numbers

Quantum can print figures in tables with up to ten characters; figures that require more than ten characters are printed as asterisks. For example, 12345678.12 appears as 12345678.1 when displayed with one decimal place, but as asterisks (*) when displayed with two decimal places. However, you can use the scale= option to apply a scaling factor before printing.

Whole numbers

Quantum can deal with whole numbers in the range −1,073,741,824 to +1,073,741,823 with an accuracy of up to six significant figures. Numbers with more than six significant figures are rounded up or down depending on the value of the remaining figures.

For some examples of how Quantum rounds figures up and down, see ‘Real numbers’ later in this chapter.

Your data will contain whole numbers whenever there are questions requiring numeric responses: for example, the question ‘How many children do you have?’ can only be answered with a whole number. If the respondent has three children, the number 3 will appear in the appropriate column in his or her data record, whereas a respondent with five children will have a 5 in that column instead.

Whole numbers are also used if you want to perform arithmetic calculations during the run, for instance to multiply a field by a number.

For further information on arithmetic in Quantum, see chapter 5, ‘Expressions’.

Real numbers

Real numbers are numbers containing decimal points. To be valid, they must have at least one digit on either side of the decimal point:

Quantum deals with real numbers of any size with accuracy up to six significant figures. Numbers with more than six significant figures have the sixth figure rounded up or down depending on the value of the remaining figures.

0.1 and 1.0 are correct

(31)

Here are some examples of rounding:

By default, Quantum calculates cell values in single precision. However, when working with very large numbers, you can produce more accurate results by using the double precision option (dp) on the a statement.

For further details on double precision, see chapter 2, ‘The hierarchy of the tabulation section’ in the Quantum User’s Guide Volume 2.

4.3 Variables and arrays

There are three types of variable — data, integer and real — each used for storing different types of information. You may create your own variables with names representing the type of information stored (for example, the variable called meals might contain a count of the number of meals eaten during the day) or you may use the ones offered automatically by Quantum.

Sometimes it is useful for a group of variables to have the same name. Each variable can then be addressed by its position in the group. This arrangement is known as an array. Arrays are discussed further in the following sections.

There is an additional type of variable, called a data-mapped, or mapvar, variable. These variables can be used to store the answers to questions, both numerical and categorical and are typically used in conjunction with one or more data-mapping file. This enables Quantum specs to be written without needing column and code information. Currently, only the qdi mapping file format is supported. Quancept CATI, Quancept CAPI and Quancept Web all produce a qdi file that can be used as a data-mapping file.

For details of data-mapped variables, see chapter 15, ‘Data-mapped variables’. 96.82529 is rounded to 96.8253

189462.1 is rounded to 189462.0 123456.5 is rounded to 123457.0 123456.444 is rounded to 123456.0 123456.445 is rounded to 123456.0

(32)

Data variables

Quick Reference

To refer to a single data variable in the C array, type:

cnumber

To refer to a field of data variables in the C array, type:

c(start_pos,end_pos)

To define a data variable, type:

data var_name sizes

before the edit section. To refer to it, use the same notation as above but replace the c with the variable’s name.

At the start of every job, Quantum provides you with an array of 1,000 data cells called C. This array is sometimes referred to as the C matrix. The individual cells are called C-variables. Each C-variable stores one ‘column’ of data. Quantum reads data from your data file into this array: we will discuss exactly how it does this in chapter 6, ‘How Quantum reads data’. For the time being, let’s say we have a very small questionnaire which uses 43 columns to store the data. Quantum will read the data for each respondent into cells 1 to 43 of the C array, one respondent at a time. The codes from column 1 of the data are copied into cell 1 of the C array, the codes from column 2 of the data are copied into cell 2, and so on. When Quantum has finished with that respondent’s data it clears out the cells in the C array and reads the data for the next respondent, placing it in cells 1 to 43 of the array.

We can access this data by defining the columns whose contents we wish to inspect or change. Let’s take the questions about color that we mentioned earlier.The printed questionnaire tells us that the respondent’s favorite color will be coded into column 15. To look at this column we would write:

c15 or c(15)

The C may be in uppercase or lowercase, and the parentheses around the column number are optional.

To refer to column 43 we would write:

c43 or c(43)

Now suppose we want to look at a field of columns such as the questionnaire serial number in columns 1 to 5. All we have to do is tell Quantum that the serial number is in a field starting in column 1 and ending in column 5, as follows:

(33)

Here the parentheses around the column numbers are obligatory.

C variables are reset to blank before a new respondent’s data is read. Thus, you can be certain that Quantum never muddles the contents of column 10 for the first respondent with those of c10 for the second respondent.

As we mentioned above, you may create your own data variables to store specific pieces of data. For instance, in a shopping survey we may want to store data about visits to Sainsburys in an array called ‘sains’ and data about visits to Safeways in an array called ‘safe’.

Before we can use these arrays, we must create them. If each array is to contain 100 cells or columns of data, we would write:

data sains 100s data safe 100s

before the edit section. Where the s at the end of each statement causes Quantum to recognize that, for example, safe1 is the same as safe(1), just as it knows that c15 and c(15) refer to the same column of data. If you created the arrays without the s, then Quantum would not recognize safe1 as being the same as safe(1).

Data variables which you create remain blank until you copy data into them. If the data about visits to Sainsburys is stored in columns 30 to 45, then we might copy this into cells 30 to 45 of the array called sains. If we then want to use this data we can write statements which refer to sains30 to sains45. Unless you subsequently change the data in sains(30,45), each time you refer to one of those cells it is exactly the same as referring to c30, c45, and so on, in the C array, and to columns 30, 45, and so on, in the data file.

In this simple example, there is not much to be gained (apart from an immediate improvement in readability) by using your own data variables. However, when you have many columns of data per respondent, or a complicated Quantum program, named data variables can be very useful for improving readability and also for providing simple yet powerful facilities for data manipulation. Here are some further examples:

To find out more about creating and using named data variables, see chapter 14, ‘Creating new variables’.

c80 means column 80 of the C array

c(130,145) means columns 130 to 145 inclusive of the C array

total(17) means cell 17 of the array called total (parentheses are optional) visits(134,136) means cells 134, 135 and 136 of the array called visits

(34)

Integer variables

Quick Reference

To define an integer variable, type:

int var_name sizes

To refer to an integer variable, type:

name[cell_number]

Integer variables store whole numbers. Strings of integer variables are called integer arrays, and each cell in the array may store any whole number from −1,073,741,824 to +1,073,741,823. At the start of each run, Quantum provides an array of 200 integer variables called T. The first cell in this array is the integer variable t1 which may store any value within the given range; the second cell in the array is the integer variable called t2 which may also store any value within the given range.

To illustrate the difference between a data variable and an integer variable, let’s suppose that our data contains the value of the respondent’s car to the nearest whole pound. If the value is £6,000, this will take up 4 columns in the data (assuming that we are only concerned with the digits) — that is, four data variables, the first of which will contain the 6, and the other three of which will all contains zeroes.

If we placed this same value in an integer variable, we would only need one variable to store the whole value because each variable can store values in the range ±1,073,741,824.

We have already mentioned that Quantum provides an integer array of 200 integer variables. You may create your own arrays using statements similar to those shown above for data variables. Suppose you have a household survey in which you have collected the value of each car that the family owns. You want to set up an integer array in which to store each value, so you write: int carval 10s

This creates an array called carval which contains ten separate integer variables called carval1 to carval10. Notice that we have followed the array size with the letter s so that we can omit the parentheses from the individual variable names. We can then copy the value of the first car into carval1, the value of the second car into carval2, and so on. If a particular household owns three cars values at £6,000, £2,500 and £500, then carval1 would have a value of 6,000, carval2 would be 2,500 and carval3 would be 500.

If you create your own integer variables, it is recommended that you name them with names that reflect their purpose in the run, as we have done in our example.

(35)

To find out more about creating and using named integer variables, see chapter 14, ‘Creating new variables’.

All integer variables have a value of zero at the start of a run, and they are not reset between respondents. If you want your integer variables to store information about the current record only, you must include statements in the edit to reset those variables to zero when a new record is read. For example, we might write:

carval1 = 0

at the start of the edit to reset the first integer variable of the carval array to zero.

You can also reset an integer variable to zero by using a clear statement.

For further information about the clear statement, see section 8.7, ‘Clearing variables’. T-variables with non-zero values are printed out at the end of the run.

Real variables

Quick Reference

To define a real variable, type:

real var_name sizes

To refer to a real variable, type:

name[cell_number]

You may define real variables and arrays to store real numbers with accuracy up to six significant figures. Values with more than six significant figures have the sixth figure rounded up or down according to the value of the extra figures.

For further information about real values, see ‘Real numbers’ earlier in this chapter.

As with integer variables, the names of real variables should give some clue to the type of information they contain. Real arrays are created by statements of the form:

(36)

This example creates a real array called liters which has five real variables named liters1 to liters5. It can store five real values, the first in liters1 and the fifth in liters5.

To find out more about creating and using named real variables, see chapter 14, ‘Creating new variables’.

Quantum also provides a set of 100 real variables named X which you may use.

All real variables start with a value of 0.0 and are not reset to zero between respondents. As an example, let’s say that the data contains information on how long, on average, each person in the household spent watching television during a given week. We want to manipulate these figures so we create an array of real variables in which to store the average viewing figures: real tvwatch 8s

This provides room for up to eight people’s figures. If our household contains four people with viewing averages of 20.8 hours, 15.75 hours, 9.75 hours and 10.0 hours, then tvwatch1 will have a value of 20.8, tvwatch2 will have a value of 15.75, tvwatch3 will be 9.75 and tvwatch4 will be 10.0 hours. The rest of the variables in the array have values of 0.0.

Real variables with non-zero values at the end of the run are not printed out automatically. If you want to see these values, you will need to write them using a report statement.

(37)

Reading real numbers from columns

Quick Reference

To read real values from the C array, type:

cx(start_col,end_col)

As we have already said, data from the questionnaire is read into columns for use during the run. When the data contains real numbers you will have to tell Quantum that the dot is to be treated as a decimal point rather than as a multicode representing a number of different answers. The way to do this is to refer to the field as cx:

cx(15,20) cx(131,135)

Here we have two fields containing real numbers: the first is six columns wide including the decimal place, which means that the number itself contains five digits, whereas the second is only five columns wide with four digits. Notice that there is no need to tell Quantum where the decimal point is.

4.4 Subscription

As we have shown above, you may refer to specific variables in integer and real arrays and cells or columns in data arrays by naming their position in the array.

For example:

Variables within an array may also be referred to using any arithmetic expression. In this case, parentheses must be used. For example:

c1 is the first column of the C array t5 is the fifth variable in the T array

time3 is the third variable in the array called time seg(2) is the second variable in the array called seg

c(t1) The column number depends on the value of t1. If t1 has a value of 10, then the variable is c10; if t1 is 67, the variable is c67.

c(t4,t5) The field delimiters depend on the values of t4 and t5. If t4 has a value of 12 and t5 has a value of 19, the column field referred to is c(12,19).

t(c4) The variable number depends on the value in c4. If c4 contains a single code in the range 1 to 9, the integer variable will be one of t1 to t9 depending on the exact

(38)

When variables are referenced in this way, the value of the expression must be positive. The expression c(t1−5) is acceptable as long as t1 is at least 5. If the expression has a zero or negative value Quantum will issue an array dimension error when it comes to read the data during the datapass. Also, if the variable refers to columns, the value of the subscript must not exceed 32,767. These are called subscripted variables and they greatly increase the flexibility with which you can write your edit.

Subscription may be used in repetitive processes to save you writing the same thing over and over again.

For an example, see section 9.5, ‘Loops’.

time(c4*23) The variable number is the result of multiplying the value in c4 by 23. As in the previous example, c4 must be single-coded in the range 1 to 9 for this example to make sense. Thus, if c4 contains just a 4, the value of the expression is 92 so the variable referred to is time92.

(39)

Quantum recognizes two types of expression — arithmetic and logical. Arithmetic expressions are used to produce numeric values and logical expressions, when evaluated, produce a value of true or false.

5.1 Arithmetic expressions

The simplest form of arithmetic expression is a single positive or negative number such as 10 or -26.5 or an integer or real variable.

Although the C array is data, columns may also be used in arithmetic when the response coded into those columns is a numeric response, such as a respondent’s age or the number of different shops he or she visited. For example, if columns 243 to 247 contain the codes 4,7,2,6 and 0 respectively the value in c(243,247) could be read as 47,260. Similarly, if columns 45 to 48 contain 7, 8, a dot and 2 respectively, the value in cx(45,48) would be 78.2.

Blank columns in a field are ignored when the codes in those columns are evaluated. Thus, if columns 20 to 21 contain the codes 6 and 7 respectively, and column 22 is blank, the codes in c(20,22) will be evaluated as 67. A similar result is produced if the blank column appears anywhere else in the field. All the examples of c(20,22) below produce an arithmetic value of 67:

+----2----+ +----2----+ +----2----+ 67 67 6 7

The same applies to multicoded columns. If you use a multicoded column as part of an arithmetic expression, the multicoded column will be ignored. The exception to this is a multicode of a digit and a minus sign which creates a negative number: a minus sign anywhere in a numeric field negates the value in the field as a whole, not just the number it is multicoded with. For example: ----+----1----+----2 5 3778 is 5378 9 0 2---+----3----+----4 12-4 is -1234 3 4---+----5----+----6 83- is -83

(40)

Combining arithmetic expressions

Quick Reference

To combine arithmetic expressions, type:

variable operator variable [operator variable ... ]

where variable is a numeric value or the name of a variable containing a numeric value, and

operator is one of the arithmetic operators +, −, * (multiply) or / (divide).

More often than not, you will want to combine numeric expressions to form a larger expression, for instance to count the number of records read with a given code in a named column.

Arithmetic expressions are linked with any of the arithmetic operators listed below:

Expressions may contain more than one of these operators, for instance: t5 + c(134,136) / otot

c(150,152) * 10 + 2.5

Quantum evaluates such expressions in the following order: 1. Expressions in parentheses

2. Multiplication and division 3. Addition and subtraction

If you wish to change this order you should enclose the expressions which go together in parentheses. The first expression in the example above will be evaluated by dividing the value in columns 134 to 136 by otot and adding the result to t5. If you change the expression to:

(t5 + c(134,136)) / otot

this adds the values of t5 and c(134,136) first and then divides that by otot. Let’s substitute numbers and compare the results. If t5=10, otot=5 and the value in c(134,136) is 125, the two versions of the expression would read as follows:

10 + 125 / 5 = 35 and (10 + 125) / 5 = 27 + (addition) * (multiplication) − (subtraction) / (division)

(41)

Where two integer expressions are combined, the result is integer (any decimal places are ignored), but if an expression contains a real then the result will be real. Therefore, if t1=5 and t2=3, then:

If you use parentheses in expressions which contain both integer and real variables, you need to take extra care to ensure that your expression is producing the correct results. Let’s look at an example to illustrate how an expression can look correct but can still produce unexpected results. If we assume that t40=2 and t41=70, the expression:

t40 * 100.0 / t41

yields a result of 2.85714 (that is, 200.0/70). The final value will be 2.85714 if the result is saved in a real variable, or 2 if it is saved in an integer variable.

If we use parentheses: (t40 / t41) * 100.0

the result is 0.0 (or 0 if saved in an integer variable). The reason for this is as follows. Because Quantum evaluates expressions in parentheses before it deals with the rest of the expression, it treats that expression as integer arithmetic. The rules for integer arithmetic dictate that real results are truncated at the decimal point, so the true result of 0.0285714 becomes 0. Any multiplication involving zero is always zero, so the final result is zero.

If you find that a run gives unexpected zero results, try looking for expressions of this type and checking whether the parenthesized part of the expression has been truncated because the integer division results in a decimal number.

t1 + 4 = 9 t1 + 4.0 = 9.0 t1 * t2 = 15 t1 / t2 = 1 t1 * 1.0 = 5.0 t1 * 1.0 / t2 = 1.66667

(42)

Counting the number of codes in a column

Quick Reference

To count the number of codes in a column or list of columns, type:

numb(cn1[’codes’], cn2[’codes’], ... )

If any columns are followed by a code reference, only those codes will be counted for those columns.

The function numb is an arithmetic expression which counts the number of codes in a column or list of columns. Its format is:

numb(cn1,cn2, ... cnn)

where cn1 to cnn are the columns whose codes are to be counted. So, if we wanted to count the number of codes in columns 132 to 135 we would type:

numb(c132,c133,c134,c135)

Notice that even though the columns are consecutive, each one is entered separately, with each column number preceded by a ‘c’. It is incorrect to define only the start and end columns of a field when using numb. Therefore it is wrong to write numb(c(132,135)) or numb(c(132,135)) and, if you write statements such as these, Quantum will flag them as errors.

Sometimes you will only be interested in certain codes, for instance you may want to know how many 1, 2 or 3 codes there are in a group of columns. In this case the function is entered as:

numb(cn’p1’,cn’p2’, ... cnn’pn’)

where p1 to pn are the codes to be counted. Only the named codes are counted — any others appearing in the columns are ignored. Let’s say our data on card 1 is as follows:

1---+----2---...---5----+----4 1 2 1 6 / / 8 6 7 9

and we want to count the number of codes in column 115 and also the number of codes in the range ‘5/8’ in columns 121 and 157. The expression would be entered as:

(43)

When Quantum checks these columns and codes, it will tell us that there are 9 codes in these columns which are within the given ranges. These codes are all four codes in column 115 (we did not specify which codes to count in that column), codes 5 and 6 in column 121 (codes 2 to 4 are outside the given range), and codes 5 to 7 in column 157 (codes 1 to 4 are outside the given range).

Generating a random number

Quick Reference

To generate a random number in the range 1 to n, type:

random(n)

in the edit section.

Quantum can generate random numbers automatically with the random function:

random(n)

where n is the maximum value the random number may take. So, to generate a random number in the range 1 to 100, the expression would read:

random(100)

The number produced may be saved for later use in an integer variable or column, thus: rnum=random(32)

c(110,112)=random(156)

When using random with columns, always make sure that the number of columns allocated to the number is sufficient to store the highest possible number that can be generated. In our example, we need three columns in order to store numbers up to 156.

random generates a different random value each time it is run, even on reruns of the same job.

If you want to retain the same set of random values between runs, copy them into the data the first time you run the job.

(44)

5.2 Logical expressions

Logical expressions are used for comparing values, codes and variables.

Comparing values

Quick Reference

To compare the values of two arithmetic expressions, type:

arith_exp log_operator arith_exp

where log_operator is one of the operators .eq., .gt., .ge., .lt., .le. or .ne.

Values are compared when you need to check whether an expression has a given value — for example, did the respondent buy more than 10 pints of milk?

Values are compared by placing arithmetic expressions on either side of one of the following operators:

If the number of pints of milk that the respondent bought is stored in columns 114 and 115, the expression to check whether he bought more than ten pints would be:

c(114,115) .gt. 10

If the number in these columns is greater than ten the expression is true, otherwise it is false. In chapter 4, ‘Basic elements’, we said that integer variables may take numeric values or the logical values true and false depending upon whether or not the value is zero. To check whether the respondent bought any packets of frozen vegetables, we can either write:

fveg .gt. 0

to check the numeric value of the variable fveg, or we can simply say: fveg

.eq. Equal to

.gt. Greater than

.ge. Greater than or equal to

.lt. Less than

.le. Less than or equal to

(45)

to check whether the logical value of fveg is true. To check whether fveg is false (that is, zero), we would write:

.not. fveg

For further information about .not., see ‘Combining logical expressions’ later in this chapter.

Comparing data variables and data constants

In virtually every Quantum run you will want to check which codes occur in which columns. This is easily done using logical expressions. There are several forms of expression depending on whether you are checking a column or a field of columns.

Data variables

Quick Reference

To test whether a data variable contains at least one of a list of codes, type:

var_name’codes’

To test whether a data variable contains none of the listed codes, type:

var_namen’codes’

To test whether a data variable contains exactly the given codes and nothing else, type:

var_name = ’codes’

To test whether a data variable contains exactly the given letter and nothing else, type:

var_name = ’letter’

To test whether two data variables contain identical codes, type:

var_name1 = var_name2

To test whether a data variable contains codes other than those listed, type:

var_nameu’codes’

To test whether two data variables do not contain identical codes, type:

(46)

To check whether a column or data variable contains certain codes, place the codes, enclosed in single quotes, immediately after the name of the column or data variable. For example:

c1’1’ c156’23’ brand’5’

The expression: Cn’p’

checks whether a column (n) contains a certain code or codes (p). The expression is true as long as column n contains at least one of the given codes. It does not matter if there are other codes present since these are ignored.

For example, to check whether column 6 contains any of the codes 1 through 4 we would type: c6’1/4’

The expression is true if c6 contains any of the codes 1, 2, 3 or 4 or any combination of those codes, regardless of what other codes may also be present. For instance:

----+----1 ----+----1 ----+----1 1 1 1 6 2 3 8 3 0 - 4 & are true, but: ----+----1 5 7 9 -is false.

In our original example we chose the codes 1 through 4. You can, of course, use any codes you like and they may be entered in any order.

The opposite of cn’p’ is: cnN’p’

which checks that a column does not contain the given code or codes. The expression is true as long as the column does not contain any of the listed codes.

(47)

For example: c478n’5/7&’

is true as long as column 478 does not contain a 5, 6, 7 or & or any combination of them. A multicode of ‘189’ returns the logical value true, because it does not contain any of the codes ‘5/7&’ whereas a multicode of ‘1589’ makes the expression false because it contains a ‘5’. The ‘=’ operator is used to check that the contents of a column are identical to either the given codes or the given letters.

The expression: c312=’1/46’

is true as long as c312 contains all of the codes 1 through 4 and 6, and nothing else. The expression: c142=’ ’

checks that column 142 is blank. The equals sign is optional when checking for blanks, so we could simply write:

c142’ ’

to check whether column 142 is blank. The expression:

c124=’A’

checks that column 124 contains the letter A and nothing else.

The ‘=’ operator may also be used to compare the contents of two data variables. For example: c56=c79

checks whether c56 contains exactly the same codes as c79. If so, the expression is true, otherwise it is false. If we have:

+----6----+ ... 1 1 5 5 the expression is true, but:

(48)

+----6----+ ... 1 1 5 5 9

yields the value false because column 79 contains a ‘9’ when column 56 does not. If you have defined your own data variables, you could write a statement of the form: brand1=c79

to check whether the data variable called brand1 contains the same codes as c79. The opposite of ‘=’ is ‘U’ (unequal):

cnU’p’

This checks whether column n contains something other than just the code ‘p’. Suppose we have two sets of data:

----+----4 ----+----4 1 1 4 5 7 9 and we write: c34u’7’

The expression is true for both sets of data. In the first example, the ‘7’ is multicoded with a ‘1’ and a ‘4’, while in the second example, column 34 does not contain a ‘7’ at all. The only time this expression is false is when column 34 contains a ‘7’ and nothing else.

References

Related documents

I like The Lord of the Rings because it’s really exciting?. It’s longer than most films, but the actors

Proprietary Schools are referred to as those classified nonpublic, which sell or offer for sale mostly post- secondary instruction which leads to an occupation..

• The development of a model named the image based feature space (IBFS) model for linking image regions or segments with text labels, as well as for automatic image

4.1 The Select Committee is asked to consider the proposed development of the Customer Service Function, the recommended service delivery option and the investment required8. It

• Follow up with your employer each reporting period to ensure your hours are reported on a regular basis?. • Discuss your progress with

• building bridges between civil society and public organisations as well as acting as a lobbying body for the Muslim charity sector; • and promoting humanitarian principles

The positive and signi…cant coe¢ cient on the post shipment dummy in the fourth column implies that prices charged in post shipment term transactions are higher than those charged

PTI: Pure Technical Inefficiency, TSE: Time Shift Effect, EE: Environmental Effects. Figure 5.2: Decomposition of technical