String definitions

<< Click to Display Table of Contents >>

Navigation:  Reference > Commands >

String definitions

DS svar = string definition,

DM mvar = string definition,

D col = string definition, ! binary data only

D spreadfield = mvar,

The last definition is a special case that is used to store values in a spreadfield. If there are more responses in the mvar than repeats in the spreadfield an error message will occur.

A string definition is written as a list of items separated by commas. Each item defines the next bit, or sequence of bits, in the variable. The length of the variable being defined will be the number of bits in the definition.

If the data is CSV then the string definition which picks up raw data will start with $* which means the column with the header which is the same as the variable being defined.

In the case of an svar, the variable takes as its true bit the first item in the string which is true; if no items are true, the svar has no true bits (value 0). If the 2nd and 7th items are true, the svar has only the 2nd bit true (value 2). An error bit can be specified in the string definition, which can force the svar to this value if there are no bits, or more than one bit, true. Alternatively, F=EMS can be used to generate automatic error monitoring for svars with more than one bit true in the definition, and to set the svar to value 0.

In the case of a mvar, the variable takes as its true bits all the items in the string that are true, so if the 1st, 78th and 114th items are true, the mvar has true bits in positions 1, 78 and 114. If no items are true, the mvar has no true bits, unless error bit E is specified, in which case the mvar takes this value.

Binary data only. The definition of cols works in the same way as defining mvars from strings. Note that the implied putdown order is always VX0123456789, regardless of whether an ORDER command is present. There may be any number of items in the string. Transfer starts at code V of the col, and continues until all the bits of the string have been copied. If the number of bits goes over a data location boundary, transfer continues at code V of the next col.

Each item in a string definition can be one of the following:

Logical expression

If a logical expression is specified, the bit is set true if the result of the logical expression is true.

Summary row

Where a summary row is needed the GP (group previous) syntax may be used. The GP is followed by the number of previous rows to be included.  For example:

dm $fred = t,$123/1-5,gp4,6,

is equivalent to:

dm $fred = t,$123/1-5,2..5,6,

Shorters

Where sequential tests are required on the same variable, the following "shorters" can be used to generate a series of items:

col / code-code

svar / bit-bit

mvar / bit-bit

ivar / iconstant-iconstant

field / iconstant-iconstant

spreadfield / iconstant-iconstant

CT(countlist) / iconstant-iconstant

svar

mvar

col

For spreadfield shorters with a range of values, the second item must be greater than the first item. It is not possible to use a backwards shorter.

In the last three shorters above, the whole variable is used. A svar or mvar by itself is equivalent to variable/1-length, and col by itself is equivalent to col/V-9, or whatever the ORDER command dictates.

When the same variable is referenced in two or more consecutive items, the variable name, with the slash, need not be repeated.

Self-reference

It is possible to refer in a string definition to the variable being defined by using the symbol "$$", instead of a variable, in a test. For example, the test:

$$/5..8, 

gives a summary bit, true if any of the 5th through 8th bits already defined are true. Note that you cannot refer to bits not yet defined; the above could be the 9th or a subsequent test, but not the 4th test.

T (true)

The item T means set this bit true. It can only be used on its own, not part of a bit definition. T can be followed by *n to set n true bits.

F (false)

The item F means set this bit false. It can only be used on its own, not part of a bit definition. F can be followed by *n to set n false bits.

E (error)

E specifies an error bit. It means set this bit true when the definition is completed, if no other bits are true. If the variable being defined is a svar, and more than one bit definition is true, then only the E bit is set true.

R (reject)

R specifies a reject bit. It means set this bit true if all the previously defined bits in the definition are false. It is usually the last item in a definition. We advise you to use E (error), if possible, rather than R (reject).

Examples of string definitions: all the following examples generate 12 bits:

dm $exam=$126/v,x,0,1,2,3,4,5,6,7,8,9,

dm $exam=$126/v-9,

dm $exam=$126,

dm $exam=$456/v-4,e,6-9,

dm $exam=$178/6,$179/1-9,$180/8,3,

dm $exam=$120-121*4/1-12,

dm $exam=$120/v.0,v.1,v.3,nv,4..9,$121/b+$122/b,$inum/3-8, 

dm $exam=$124-127/0-9,10..100,>99,

dm $exam=$345-348/b,'&&&&','----',1-7,>7,e,

dm $exam=t*3,f*3,t,f,t,f,t,f,

dm $exam=$swhen/1-12,

dm $exam=$swhen/1-11,e,

dm $exam=$mthis/b,s,m,$mthat/2-10,

dm $exam=$mthis/$iw1,$iw2,$iw3,f*9,

dm $exam=$i5/1-4,gp4,5-7,gp3,8,99,e,

dm $exam=ct($233)/0-10,e,

dm $exam=$mm/(1+6).(2+7),3+(10.11),21-30,

dm $123=$swhen/1-12,

dm $exam=$*/1-12,

 

Text can be embedded within the string definition using colon or semicolon:

dm $fred= $128/1:'Header\One',2:'Two',

dm $fred= $128/1;'Header\One',2;'Two',

are the same as:

dm $fred=$128/1,2,

x = 'Header\One;Two',

 

The number of texts included must match the number of definitions so far:

dm $fred= ;'Header\',$128/1-2;'One;Two',3-4;'Three;Four',

is the same as:

dm $fred=$128/1-4,

x = 'Header\One;Two;Three;Four',