import data
is a widget which allows survey programmers to define and populate variables with data. These are not survey variables, and they do not exist in the data. These variables exist in programming only and are used to facilitate survey function.
Syntax
Use import data
to name a variable, and then assign a value to it. The value may be a hash or a hashref, and as such accepts fetch_cell
and fetch_row
. Multiple variables may be defined.
# Define import_data: (variablename => value) # Reference $variablename # With fetch_row import_data: ( hrefname => fetch_row( name => 'sheetname', row => row id ) ) # Or fetch_cell import_data: ( variablename => fetch_cell( name => 'sheetname', row => row id, column => col id ) )
Tags
Tag | Description |
---|---|
prefix |
Adds a prefix to all variable names with a given string. |
Example
import data
is most useful when requirements are complex, and programming is aided by being able to access data stored outside of the survey code, such as in a sheet. Conjoint programming makes use of import data
, and there are other applications as well.
Suppose a survey requires that a list of price ranges for a product display on screen for the respondent. There are 40 values within in each, and the exact set of ranges that display are based on inputs to earlier questions. Finally, suppose that there are 200 (or 2,000, or 20,000...) different ranges that could potentially be displayed. There is no utility to having this data take up space within the survey source, nor appear in the data set. In this case, we'll store it all in a spreadsheet and use import data to access ranges.
Download the spreadsheet used for this example here: priceranges.xlsx
The import data
tag defines the variable rangetext
, the value of which is the relevant row from the sheet priceranges. We use this data to build an unordered HTML list, where each value is a given column from the priceranges sheet.
1. Please select the smallest amount you've spent on this product: type: radio 0. $0 1. $1 2. $2 3. $3 4. $4 5. $5 6. $6 7. $7 8. $8 9. $9 1A. Please select the largest amount you've spent on this product: type: radio 1. $1 2. $2 3. $3 4. $4 5. $5 6. $6 7. $7 8. $8 9. $9 RESP. Respondent Type type: text invisible: y cvalue: {"1" . $Q1 . $Q1A} newpage import_data: ( rangetext => fetch_row( name => 'priceranges', row => $QRESP ) ) <ul> <li>$[* $rangetext ->{range1} *]</li> <li>$[* $rangetext ->{range2} *]</li> <li>$[* $rangetext ->{range3} *]</li> <li>$[* $rangetext ->{range4} *]</li> <li>$[* $rangetext ->{range5} *]</li> <li>$[* $rangetext ->{range6} *]</li> <li>$[* $rangetext ->{range7} *]</li> <li>$[* $rangetext ->{range8} *]</li> <li>$[* $rangetext ->{range9} *]</li> <li>$[* $rangetext ->{range10} *]</li> <li>$[* $rangetext ->{range11} *]</li> <li>$[* $rangetext ->{range12} *]</li> <li>$[* $rangetext ->{range13} *]</li> <li>$[* $rangetext ->{range14} *]</li> <li>$[* $rangetext ->{range15} *]</li> <li>$[* $rangetext ->{range16} *]</li> ...etc
Comments
0 comments
Please sign in to leave a comment.