Professional > Table scripting > Working with metadata > Working with versions > Changing the base to reflect the version
 
Changing the base to reflect the version
Sample script file: PercentageOnElementsAsked.mrs
This example script is based on the Short Drinks sample data set. To run examples using the Short drinks sample data set, you need access to a SQL Server installation on which the Short Drinks sample database has been restored, and appropriate user access rights. For more information, see Restoring the Short Drinks sample database. For information on running the example scripts, Running the sample table scripts.
In UNICOM Intelligence Reporter you can use the IsElementInVersions function to determine whether a particular element exists in a particular version of the metadata. This can be used to take into account the fact that not all categories or all variables may be available in all versions of a questionnaire. For example, in the Short Drinks data set the Socioeconomic Class variable (sclass) occurs in versions 1-4 of the questionnaire and the Fulltime Parent category of that variable exists only in versions 3 and 4.
One way to use this function is in an expression that defines a base element, for example:
base('<variable_name>.IsElementInVersions
({category_name}, DataCollection.MetadataVersionNumber)
AND <variable_name> IS NOT NULL)')
Note that in these examples, the expression is presented on multiple lines for clarity. In practice you should specify the expression without line breaks.
For each record in the case data, the IsElementInVersions function checks to see if the specified category was available in the version of the questionnaire that the respondent was asked (this is determined by the value of the DataCollection.MetadataVersionNumber variable). If the category was available and the question itself was asked, the expression returns True, otherwise it returns False. The base element counts the number of respondents for which the expression is True.
The following expression shows the test being carried out on the Fulltime Parent category of the Socioeconomic class variable.
base('sclass.IsElementInVersions
({PARENT},DataCollection.MetaDataVersionNumber)
AND (sclass IS NOT NULL)')
An example of the output of this expression for the Fulltime Parent category for selected respondents is shown in the following table.
Respondent
Response
Metadata version
Result of Expression
15
{w_collar}
2
False
61
{not_work}
3
True
62
{parent}
3
True
68
null
3
False
87
{shopkeeper}
4
True
98
null
5
False
For respondents 15 and 98 (who were asked metadata versions 2 and 5) the expression returns False because the parent category did not exist in those versions. For respondent 68 the expression returns False because the respondent was not asked the sclass question (the response is null). For respondents 61, 62, and 87, the expression returns True because the metadata version asked contains the parent category (notice that this is independent of the actual answer given).
See also
Example
Working with versions