Dynamically generating a different value set within a questi

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
erikee33
Posts: 7
Joined: January 26th, 2016, 7:13 am

Dynamically generating a different value set within a questi

Post by erikee33 »

Hi!
I am reading through the manuals to learn how to create a dynamically generating value set for a question (which happens to be within a roster). For example, I want to ask the respondent where he has worked and based upon which country, generate an option for districts, and then based upon district, generate an option for city etc. I have created multiple value sets within the single question in the dictionary file.
I am confused as to whether I need to go through the hassle of creating a look up file or if I can just use program logic and multiple value sets for the question. It looks like they're suggesting I have to create a lookup file to do that. Is there no way to avoid a lookup file?

Please help!
Thank you,
Erika
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Dynamically generating a different value set within a qu

Post by josh »

There is no need to create a lookup file. In many cases users have their data for country, district, city... in an Excel file so it makes sense to use a lookup but it is certainly possible to do it without one. The advantage of the lookup file is that if it is structured correctly, it specifies the link between country and district as well as the link between district and city i.e. it tells you which cities are in the district that the users chooses. Without the lookup file you will have to specify this linkage another way.

The simple way to do this, if you don't have a lot of districts, is to just use if statements in your logic to set the value set for the city based on the district chosen:

Code: Select all

PROC CITY
onfocus
if DISTRICT = 1 then
    setvalueset(CITY, CITY_DISTRICT1_VS1);
elseif DISTRICT = 2 then
    setvalueset(CITY, CITY_DISTRICT2_VS1);
elseif DISTRICT = 3 then
    setvalueset(CITY, CITY_DISTRICT3_VS1);
etc..
If you have a lot of districts and cities then this can require a lot of typing. An alternative is to use the coding scheme to determine the hierarchy of districts and cities. You would include the district code in your city code so that you can dynamically create a value set from the cities in the districts chosen. For example if in district 1 you have three cities you would use codes 11, 12 and 13. Then for the cities in district 2 you would use 21, 22, 23... Then instead of using fixed value sets in the dictionary you would use a loop to iterate overall the cities in the district chosen and construct the value set using arrays. This requires some more advanced logic so you may want to stick with the first option if you are not comfortable with loops and arrays. You can see an example in the section on "cascading questions" in http://teleyah.com/cspro/DCJune2015/05- ... -entry.pdf
erikee33
Posts: 7
Joined: January 26th, 2016, 7:13 am

Re: Dynamically generating a different value set within a qu

Post by erikee33 »

Thank you so much for the help! I typed it up (thankfully it's for a small country :) and used basic program logic. Thanks again for your help. It's much appreciated.
Post Reply