• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
      • Introduction to Data Entry
      • Data Entry Application
      • Data Entry Editing
      • CAPI Data Entry
        • Introduction to CAPI
        • CAPI Features
        • Capture Types
        • Questions
          • Question Text
          • Create Helps for Fields
          • Enter Question Text
          • Create Fills in Questions
          • Create Conditional Questions
          • Question Text Properties
          • Edit Styles
          • Change Formatting
          • Add Images
          • Insert Link in Question Text
          • Define Languages
          • Use Multiple Languages
          • HTML Question Text
          • QSF Question Text Template Object
          • Question Text Macros
        • Multimedia
        • CAPI Strategies
        • How to ...
      • Network Data Entry
      • Android Data Entry
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Create Fills in Questions

Fills are used to customize question text based on respondents' specific characteristics. This is done by embedding CSPro logic into the text as a template expression and surrounding it with one of the supported delimiters: ~~, ~~~, and <? ?>.
Fills may contain any valid CSPro logic expression that evaluates to a string or numeric value, or binary data. Logic expressions may include dictionary items, variables, occurrence labels, user-defined functions, as well as any built-in CSPro functions and operators.
Fills with Dictionary Items or Variables
Enter some question text that needs to be customized. For words or phrases that need to be filled, enter a dictionary item or variable with ~~ characters before and after. For example:
Can I speak with <b>~~FIRST_NAME~~</b> now?
When the entry system comes to this text, it will insert the person's FIRST_NAME value into the question text:
Can I speak with <b>Marjorie</b> now?
Can I speak with
<b>Allyson</b> now?
When used with numeric values, the fill uses the value code. For example, ~~SEX~~ might be 1 or 2. If you want to use the value label, you can use the getvaluelabel function:
How old was <b>~~FIRST_NAME~~</b> when they completed <b>~~getvaluelabel(HIGHEST_GRADE_COMPLETED)~~</b>?
Fills with Occurrence Labels
You can customize the question text by inserting an item or group's occurrence labels into the text. For example:
How much did you spend on <b>~~getocclabel()~~</b> in the last month?
Fills with User-Defined Functions
You can insert the return value of a user-defined function into the question text. The function can return either numeric or string values. For example:
Thinking now about <b>~~FIRST_NAME~~</b>, what is <b>~~SexPronoun()~~</b> age?
In logic, a user-defined function must be declared, as in:
function string SexPronoun()

   
recode SEX -> SexPronoun;
           
1   -> "his";
               -> 
"her";
   
endrecode;

end;
HTML in Fills
You can use HTML tags in order to dynamically format fills using logic. If you use HTML tags, you must surround the fill with three tildes (~~~) instead of two. This tells CSPro not to escape the tags when substituting the fill value. If you use the standard two tildes ~~, the literal HTML will substituted instead of the formatted value.
For example the question text:
You have entered the following household members:

~~~householdMembers~~~
with the following logic:
householdMembers = "<ul><li>Bouba</li><li>Frank</li><li>Chen</li></ul>";
will result in:

You have entered the following household members:

  • Bouba
  • Frank
  • Chen
Or more realistically:
householdMembers = "<ul>";

do numeric ctr = 1 while ctr <= totocc(PERSON_REC)
    householdMembers = householdMembers + 
maketext("<li>%s</li>", encode(strip(NAME(ctr))));
enddo;

householdMembers = householdMembers + 
"</ul>"
See also: Question Text, HTML Question Text