In this article
1: Summary
SmartHub allows you to recode values using two flexible transformation types:
recoding ranges— map numeric intervals to string values (e.g., scores to categories).recoding values— map one string to another (e.g., harmonizing labels or codes).
These recodes are declared as standalone entities and then referenced using the recode() function inside table transforms.
2: Using recoding ranges
This entity maps numeric ranges to new values.
recoding ranges #dimension3point {
intervals: rightopen
mapping {
to: "1"
from: 3.5..
}
mapping {
to: "2"
from: 2.5..3.5
}
mapping {
to: "3"
from: ..2.5
}
}2.1: Properties:
| Property | Description |
intervals | Defines how range endpoints behave. Options: leftopen, rightopen, open, closed.
|
mapping | One or more from → to blocks defining value conversions. from accepts range syntax (e.g., ..2.5, 2.5..3.5, 3.5..).
|
Tip: Ranges must not overlap. Use consistent endpoints based on the interval mode.
3: Using recoding values
This entity maps strings to strings. Useful for normalizing data labels or merging values.
recoding values #mappingWave1 {
mapping {
from: "R"
to: "RD"
}
mapping {
from: "D"
to: "RD"
}
}This approach can be used with variables of type text, singleChoice, or any string-based field.
4: Applying Recodes in Transforms
Once defined, use recode() to apply mappings to variable values:
value: recode(:myVariable, @dimension3point)
Or for string-based mappings:
value: recode(.response:EV1039, @mappingWave1)
5: Example: Recode Average Scores
variable singleChoice #threePoint {
value: recode(dimensionScore:dimensionScoreValue, @dimension3point)
label: "Distribution"
required: true
option code { code: "3", label: "Unfavorable" }
option code { code: "2", label: "Neutral" }
option code { code: "1", label: "Favorable" }
}6: Best Practices
Use meaningful
tovalues like"Favorable"or"High"where appropriate.Stick to clear naming for recoding entities (e.g.,
#waveMapping,#score3pt).Always test range boundaries—especially if using open vs. closed intervals.
If recoding numeric to string, ensure the target variable is a
singleChoiceortext.