# Clean and Define - Group Operations

A Group operation contains one or many expression groups and each group contains one or many Clean/Define expressions. An expression group can have an optional filter describing which respondents that will be affected by the expressions within the group.

Three types of Clean/Define expressions are possible to define within a group:

• Set expression
Sets new values from an assignment expression (action).
• Logical define expression
Fills categorical questions with data created from a logical expression (action).
• Arithmetical define expression
Fills quantitative questions with data created from an arithmetical expression (action).

Each of these expressions can have an optional filter (condition) that will restrict the operation to respondents that satisfy the expression.

When combining group filters and expression conditions the following table shows the possible logical combinations.

 Group filter Expression condition Result True True True True False False False True False False False False Not set True True Not set False False True Not set True False Not set False

### Group Filter

Filter  [!]\QuesList.SubqList.RowList = ValueList
A normal filter expression including logical operators, parenthesis, intervals, lists, special codes and frequencies.

Set Expression

Condition - If
An optional condition can be set that will restrict the operation to respondents that satisfies the If expression.

Syntax
See Filter

Action - Then
An assignment expression that will set values (codes, quantities or special codes) to each respondent that satisfies the optional group filter and condition.

Syntax

`[!]\QuesList.SubqList.Rowlist = [!,]ValueList `

Or

`\QuesList.SubqList.Rowlist = SpecialCode `

Left hand side

A Question/Sub question/Row reference including intervals (,,) and lists (,). An exclamation mark states that all values on the right hand side will be removed instead of set.

Right hand side

A Special code or a value list containing one or many values that will be set. An exclamation mark states that all values (answers) will be removed prior to setting the given values.

Special codes

Value list
 v Single value (code or quantity) v,v,…,v Multiple values for M/RM. !,v,v,…,v All answers will be removed prior to setting the new values (M/RM). The special case ”!,v” for all other data types is equal to “v” since only one value is possible.

Examples

• Set \Q3.b to 10 for each respondent that satisfies (\Q1.a=1 AND \Q2.a.1=13:19)
`<group filter=”\Q1.a=1”>   <set condition=”\Q2.a.1=13:19” action=”\Q3.b=10”>   </group> `
• Remove all answers from \Q4.a.1 to \Q4.a.10 and then set \Q4.a.1 to \Q4.a.10 to 2, 3 and 4 for each respondent that satisfies (\Q10:Q12.a:b.1=1 | \Q13.a=5)
`<set condition=”\Q10:Q12.a:b.1=1|\Q13.a=5” action=”\Q4.a.1,,10=!,2,3,4” /> `
• Set \Q1.a as ‘not asked’ for all respondents
`<set action=”\Q1.a=!?” /> `
• Remove code 1  from \Q1.a for all respondents
`<set action=”!\Q1.a=1” /> `
• Set all components in Q1 to Q5 to not answered
`<set action=”\Q1,,Q5=-“ /> `
• Set all components in sub questions a, b, c and f in Q1 to not answered
`<set action=”\Q1.a,,c,f=-” /> `
• Set rows 1, 10 and 12 in all sub questions in Q1 to not answered
`<set action=”\Q1.1,10,,12=-“ /> `

Logical Define

Condition - If

An optional condition can be set that will restrict the operation to respondents that satisfies the If expression.

Syntax
See Filter

Action - Then

A logical expression that fills a categorical question with evaluated data (true/false).

Syntax
See Filter

Location

A reference to the categorical row that will have its data filled or updated.

Examples

• Evaluate \Q1.a=1 and fill the second row in \Q2.a with true/false values
`<logic action=”\Q1.a=1” location=”\Q2.a.2” /> `
• Evaluate \Q3.b=10 for each respondent that satisfies (\Q1.a=1 AND \Q2.a.1=13:19) and fill the first row in \Q10.a with true/false values.
`<group filter=”\Q1.a=1”>   <logic condition=”\Q2.a.1=13:19” action=”\Q3.b=10” location=”\Q10.a.1” /> </group> `

Arithmetical Define

Condition - If

An optional condition can be set that will restrict the operation to respondents that satisfies the If expression.

Syntax
See Filter

Action - Then

An arithmetical expression that fills a quantitative question with evaluated data.

Syntax

• N
Numeric value
Quantitative question: evaluates to a series of numerical answers.

Categorical question: evaluates to a series of codes (default) or to a series of categorical values (0/1).

• serial
Fills a numeric question with a respondent index starting from 1.
• Function
ABS( expression)absolute value,

NINT( expression)round to nearest integer,
MAX( expression)maximum value,
MIN( expression)minimum value,
INT( expression)convert to integer

Arithmetical operators: +, -, *, /, **

Parentheses can be used to override operator precedence.

Location

A reference to the quantitative row that will have its data filled or updated.

Examples

• Fill the second row in \Q2.a with 50 for all respondents.
`<arithmetic action=”(2 + 3) * 10” location=”\Q2.a.2” /> `
• Fill the first row in \Q1.a with a respondent number ([1..N]).
`<arithmetic action=”(2 + 3) * 10” location=”\Q1.a.1” /> `
• Evaluate INT(<10>\Q20.b.1 – 100) for each respondent that satisfies (\Q1.a=1 AND \Q2.a.1=3:9) and fill the first row in \Q10.a.
`<group filter=”\Q1.a=1”>   <arithmetic condition=”\Q2.a.1=3:9” action=”INT(<10>\Q20.b.1 – 100)” location=”\Q10.a.1” /> </group>`