GENERATE Statements
Data can be generated by the program with a GENERATE statement. Data can be moved or blanked. FIELD question responses can be added, removed or netted. GENERATE statements, such as GOTO and EXPRESSION statements, are frequently based on condition statements.
The general syntax for a GENERATE statement is:
!GENERATE,subtype,label or location,response code or punch or length,offset
GENERATE statements require a subtype and a receiving question. The rest of the parameters depend on the subtype. If a data location reference is used, brackets ([ ]) should be placed around the data location.
NOTE: Back-references to FIELD questions previously asked will still show the response at that time, even if the question’s data has been altered or blanked with a GENERATE statement. Place a FIELD question subtype of USE_PREVIOUS with an ALIAS= parameter on the updated location to update the answer array.
All GENERATE subtypes have a maximum of 5000 columns that can be accessed at one time. If you need more than that, simply do multiple GENERATE statements.
Valid Subtypes
- Add_Code
- Blank_Text_Pointer
- Clear_Data
- Compress_Data
- Copy_Data
- Erase_Answer_Array
- Net_Codes
- Remove_Code
- Remove_Shared_Response_Codes
- Replace_Codes
- Replace_Codes_From_Question
- Upshift/Downshift
ADD_CODE
Shortform: GEN,ADD
A GENERATE,ADD_CODE is used on the responses to a FIELD question’s response list to add a code or multiple codes to the list. The GENERATE,ADD_CODE statement is particularly useful to present multiple questions using the same question list, but requiring different responses depending on a prior response.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,ADD_CODE statement is:
!GENERATE,ADD_CODE,label or location,codes
If a label is used, a response code that exists in the question’s response list is required. When adding responses, other responses are not affected.
EXAMPLE:
{ QBRANDS: 20 HIDE !FIELD 1 Item 1 2 Item 2 3 Item 3 4 Item 4 5 Item 5 } {!IF OLDBRAND(1) !GENERATE,ADD_CODE,QBRANDS,3 } Or { QBRANDS: 20 HIDE !FIELD 1 Item 1 2 Item 2 3 Item 3 4 Item 4 5 Item 5 } {!IF OLDBRAND(1) !GENERATE,ADD_CODE,[20],3 }
In the first example, if question OLDBRAND had a response of 1, the program will add a 3 response to the question label QBRANDS.
In the second example, if question OLDBRAND had a response of 1, the program will add a 3 response to the data location 20.
For multiple-response FIELD questions, the GENERATE,ADD_CODE will add the new response into any remaining available blank columns of that FIELD question. If there is no more room, Survent will abort with a blow error.
BLANK_TEXT_POINTER
Shortform: GEN,BLANKTEXT
The GENERATE,BLANK_TEXT_POINTER is used to remove text pointers from the data, the associated text in the text data area, and the answer from the answer array, leaving the space available in the text data area.
NOTE: This subtype only works with TEXT type questions.
The syntax for the GENERATE,BLANK_TEXT_POINTER statement is:
!GENERATE,BLANK_TEXT_POINTER,label or location
Since text pointers always have a length of one, no length is specified. If you blank a TEXT question with a GENERATE,BLANK_TEXT_POINTER statement you may RESET over it, but the text blanked by the GENERATE is not restored.
CLEAR_DATA
Shortform: GEN,CLEAR
The GENERATE,CLEAR_DATA statement is used to blank data on FIELD questions. Use caution with this because the data cannot be recovered once blanked. This is used to blank temporary data from a section of a data file or when going backwards using GOTO statements.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,CLEAR_DATA statement is:
!GENERATE,CLEAR_DATA,label or location,length
If you reference a question label, the default length is the question’s length. The default length for data locations is one.
EXAMPLE:
{ QCLEARDATA: !IF NUMHOUSE < 2 !GENERATE,CLEAR_DATA,NUMBEROFHOMES,1 }
This would blank the data in the question NUMBEROFHOMES if the response to NUMHOUSE was less than 2.
COMPRESS_DATA
Shortform: GEN,COMPRESS
The GENERATE,COMPRESS_DATA subtype is intended for use only to collapse codes across multiple field questions or with a data field where all questions and gaps are coded with the same length.
NOTE: Do not use this to compress variables of different code or value lengths.
The program uses the starting location and length to determine whether to collapse the following fields. If a following field is blank for the duration of the first question’s width, it is compressed out, otherwise it stays in its relative position.
The GENERATE,COMPRESS_DATA has no column limit. You can compress as many codes as you want. However if you compress more than 240 columns worth of codes and then you back up over the GENERATE,COMPRESS_DATA, Survent will not remove the codes.
The syntax for the GENERATE,COMPRESS_DATA statement is:
!GENERATE,COMPRESS_DATA,label/location.width of codes, width to compress
This could be useful if you used separate adjacent questions to collect answers and you now want to move the data so it is in one field with no blanks (i.e., “01 02 05” becomes “010205”). This could be handy to set up codes for a FIELD,INCLUDE_EXCLUE reference later on in the questionnaire.
COPY_DATA
Shortform: GEN,COPY
The GENERATE,COPY_DATA subtype copies data from one question or location to another. Any data already in the receiving location is replaced with the data from the sending question. GENERATE,COPY_DATA may also be used to move TEXT data to other TEXT questions or to and from VARIABLE questions.
NOTE: When writing from TEXT to VARIABLE questions, use the offset feature to access columns beyond 5000. The maximum size of any question is 5000.
The syntax for the GENERATE,COPY_DATA statement is:
!GENERATE,COPY_DATA,to label or location,from label or location,length
Or, for writing long TEXT questions to VARIABLE questions:
!GENERATE,COPY_DATA,to label or location,from TEXT question label,length,offset
GENERATE,COPY_DATA replaces any data that is already in the question it moves a response to. The sending field still has a copy of the data after the move has taken place. The length is optional. It defaults to the length of the receiving question if using labels, or one if using data locations.
EXAMPLE:
{ QCOPYDATA: !IF X(FEB) < X(JAN) !GENERATE,COPY_DATA,NEWBRAND,BRAND }
If the response to question FEB is less than the response to question JAN, the program will move the data from question BRAND to question NEWBRAND.
If you have a series of questions to move, using a length will let you move them in one block as opposed to moving the questions one by one.
EXAMPLE:
{ QCOPYDATA2: !GENERATE,COPY_DATA,NEWBRAND,BRAND,10 }
This example copies all data starting at question BRAND for a length of 10 columns, to NEWBRAND for a length of 10 columns.
You can use the GENERATE,COPY_DATA to copy a TEXT question to a VARIABLE question or to another TEXT question. To do this you must always reference the TEXT question by its label.
You can copy a VARIABLE question to a TEXT question, but you must specify the length.
To get all the data from a TEXT question (which may have up to 5000 columns) to the regular data area, you can also write from a TEXT to a VARIABLE,
EXAMPLE:
{ QVARIABLE: .5000 HIDE !VARIABLE } { QTEXT: !TEXT } { QCOPYDATA: !GENERATE,COPY_DATA,QVARIABLE,QTEXT }
ERASE_ANSWER_ARRAY
Shortform: GEN,ERASEANSWER
The GENERATE,ERASE_ANSWER_ARRAY subtype will blank out the answer array for a question. This will not affect the data, just what shows on the screen when you do back-references.
The syntax for the GENERATE,ERASE_ANSWER_ARRAY statement is:
!GENERATE,ERASE_ANSWER_ARRAY,label
Use this to eliminate ‘Other’ responses when doing ALIAS=xx, for instance.
NET_CODES
Shortform: GEN,NETS
The GENERATE,NET_CODES subtype works like the ADD_CODE subtype, except that rather than referencing specific codes, data is netted based on the data in another question.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,NET_CODES subtype is:
!GENERATE,NET_CODES,to label or location,from label or location,-length
The receiving question or location and sending question or location are required. The length is used if you have more than one contiguous question or set of columns to act on or you only want to affect part of a question. When specifying a length, each column of the sending question or location is netted from its corresponding column of the sending question or location.
The default width, if none is specified, is the width of the labeled question, or one if using data locations.
The GENERATE,NET_CODES subtype nets the responses from one sending question to another. To net together multiple questions, simply add more GENERATE,NET_CODES statements. For instance, one might wish to net the response to the “best” pizza question to the “other” pizzas known about question, to see all pizzas known about.
If a dash (-) is placed before the length on a GENERATE,NET_CODES subtype, all the columns of the sending question and length will be netted into the first column of the receiving question.
EXAMPLE:
{ QNETCODES: !GENERATE,NET_CODES,NEWBRAND,BRAND }
This example nets the codes from the question BRAND to NEWBRAND. After the net, NEWBRAND will have its original responses as well as any different responses from question BRAND.
EXAMPLE:
{ QNETCODES2: !GENERATE,NET_CODES,39,23,-3 }
This example nets the codes from column 23-25 (23,-3) all into column 39 (because of the -).
For multiple-response FIELD questions, the GENERATE,NET_CODES will net the new responses into any remaining available blank columns of that FIELD question. If there is no more room, Survent will abort with a blow error.
REMOVE_CODE
Shortform: GEN,REMOVECODE
A GENERATE,REMOVE_CODE is used on the responses to a FIELD question’s response list to remove a code or multiple codes from the list.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,REMOVE_CODE subtype is:
!GENERATE,REMOVE_CODE,label or location,codes
If a label is used, a response code that exists in the question’s response list is required. When removing responses, other responses or punches are not affected. The GENERATE,REMOVE_CODE subtype will remove the response then left-justify the remaining responses in the FIELD question’s data location.
EXAMPLE:
{ QREMOVE: !GENERATE,REMOVE_CODE,BRANDS,1 }
This example removes a 1 response from the question BRANDS. Any other responses will remain in the data.
REMOVE_SHARED_RESPONSE_CODES
Shortform: GEN,REMOVESHAREDRESPONSECODE
The GENERATE,REMOVE_SHARED_RESPONSE_CODES subtype works like the REMOVE_CODE subtype, except that rather than referencing specific codes, data is removed based on the data in another question.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,REMOVE_SHARED_RESPONSE_CODES subtype is:
!GENERATE,REMOVE_SHARED_RESPONSE_CODES,to label or location,from label or location,-length
The receiving question or location and sending question or location are required. The length is used if you have more than one contiguous question or set of columns to act on or you only want to affect part of a question. When specifying a length, each column of the sending question or location is removed from its corresponding column of the sending question or location.
The default width, if none is specified, is the width of the labeled question, or one if using data locations.
The GENERATE,REMOVE_SHARED_RESPONSE_CODES subtype takes all the responses out of the receiving question that are in the sending question (or all of the punches if referring to locations). Only those responses unique to the receiving question will remain. This is the opposite of the GENERATE,NET_CODES netting function.
EXAMPLE:
{ QREMOVE: !GENERATE,REMOVE_SHARED_RESPONSE_CODES,NEWBRAND,BRAND }
This statement takes all responses out of question NEWBRAND that were in question BRAND.
Only responses unique to NEWBRAND will remain.
For multiple-response FIELD questions, the GENERATE,REMOVE_SHARED_RESPONSE_CODES subtype will take out the duplicate or matching responses then automatically left-justify the remaining responses in the FIELD question’s data location.
REPLACE_CODES
Shortform: GEN,REPLACECODE
The GENERATE,REPLACE_CODES subtype allows you to replace a specific code in a question with a different code or codes. This can be very useful in coding situations, where you want the new code to replace the “OTHER” code in the question being coded.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,REPLACE_CODES subtype is:
!GENERATE,REPLACE_CODES,question changed,code replaced,new code(s)
EXAMPLE:
{ QREPLACE: !GENERATE,REPLACE_CODES,Q32,95,97,98 }
This statement would replace code 95 with codes 97 and 98 in Q32.
The GENERATE,REPLACE_CODES subtype keeps response order intact on FIELD questions. You can add any code that is the proper width for the question, even if it is not on the code list for the receiving question. If you try more codes than will fit in the question space, it just adds as many as it can.
REPLACE_CODES_FROM_QUESTION
Shortform: GEN,REPLACECODEFROMQUESTION
The GENERATE,REPLACE_CODES_FROM_QUESTION subtype replaces a code in a question with codes entered in a different question. This can be very useful in coding situations, where you want the new code(s) to replace the “OTHER” code in the question being coded.
NOTE: This subtype only works with FIELD type questions.
The syntax for the GENERATE,REPLACE_CODES_FROM_QUESTION subtype is:
!GENERATE,REPLACE_CODES_FROM_QUESTION,question changed,code replaced,questions from
EXAMPLE:
{ QREPLACE: !GENERATE,REPLACE_CODES_FROM_QUESTION,Q23,95,Q23OTCD1,Q23OTCD2 }
This example would replace the 95 code in Q23 with the codes entered in Q23OTCD1 and Q23OTCD2.
You can have as many codes as you want in the “from” questions, it will insert those codes in the list at the point you are replacing the code(s).
The GENERATE,REPLACE_CODES_FROM_QUESTION subtype keeps response order intact on FIELD questions. You can add any code that is the proper width for the question, even if it is not on the code list for the receiving question. If you try more codes than will fit in the question space, it just adds as many as it can.
UPSHIFT/DOWNSHIFT
The GENERATE,UPSHIFT subtype will upshift all characters within a VARIABLE or TEXT type question. The GENERATE,DOWNSHIFT subtype will downshift the characters.
The syntax for the GENERATE,UPSHIFT (DOWNSHIFT) subtype is:
!GENERATE,UPSHIFT,label !GENERATE,DOWNSHIFT,label
Example:
{ QNAME: !VARIABLE,,50,2 } { QUPSHIFT: !GENERATE,UPSHIFT,QNAME }
This example will upshift all of the letters in the question QNAME.