This article describes how to bring a variable over from one linked data set to another. This is useful when you wish to make calculations that require all your variables to be in the same data set.
Requirements
- A document with two data sets loaded in the Data Sets tree.
- A Relationship between the files. See How to Link Data Sets Together in a Document for details.
- Note, this approach can only be used in a One to One or One to Many relationship where you are copying data from a data set that represents the One part of the relationship. It cannot be used with a Many to Many relationship which is instead performing Data Fusion.
Method
1. Select the Data Set in the Data Sets tree where you wish to add the variable. In this example, our data set is called File1 and we are bringing a variable over from File2.
2. In the Data Sets tree, hover over any variable and click the Plus (+) then select Custom Code > JavaScript - Numeric or JavaScript - Text depending on the format of the variable you wish to copy.
Note that a Nominal, Ordinal, or Date/Time variable should be set up as a numeric JavaScript variable.
3. Select the variable in the second Data Set and drag it over to the JAVASCRIPT CODE field in the object inspector. This will automatically add the relevant code.
You can also enter this manually using the below format:
Q.GetValue('source_variable_name', 'source_data_set')
The source_variable_name will match Properties > GENERAL > Name, and the source_data_set in this case would be File2.
4. Change Properties > Structure to the correct data type.
5. OPTIONAL: If you are copying over a categorical variable such as Nominal or Ordinal, it will only carry over the values. You can, however, copy over the labels by doing the following:
- To copy the labels, select the source variable in the Data Sets tree and go to Properties > DATA VALUES > Labels > Export > CTRL + C.
- To then apply this to your new variable, select it in the Data Sets tree and go to Properties > DATA VALUES > Labels > Import > CTRL + V > OK.
Next
How to Link Data Sets Together in a Document