Dear Sir,
I am using single variable in rotation roster. And count how many male member in this table.
Thanks
Ramesh
Count function not run
Re: Count function not run
I don't understand your question. What exactly is the problem?
-
- Posts: 8
- Joined: January 10th, 2014, 5:57 am
Re: Count function not run
Dear Sir,
I am want to know how to select random name from without table view roster.
Thanks
Ramesh
I am want to know how to select random name from without table view roster.
Thanks
Ramesh
- Attachments
-
- PACS II Household.zip
- (5.24 KiB) Downloaded 332 times
Re: Count function not run
If I understand correctly you have the repeating form SECTION_9A_FORM and you want to select a name at random from one of the instances of that form. The total number of instances (repetitions) of the form can be had using the function totocc() with the name of the form i.e. totocc(SECTION_9A_FORM). You can use the function random with 1 as the lower limit and totocc(SECTION_9A_FORM) as the upper limit to choose the name at random. Then to get the name you use random number as a subscript into the name variable. Something like:
Code: Select all
numeric pick = random(1, totocc(SECTION_9A_FORM));
NAME = Q902BB(pick);
-
- Posts: 8
- Joined: January 10th, 2014, 5:57 am
Re: Count function not run
Hi Sir,
Thank you for this syntax. This is good for that condition.
My condition is random selection from "Q902B What is the type of school?" is selected 1 only.
Thank you for this syntax. This is good for that condition.
My condition is random selection from "Q902B What is the type of school?" is selected 1 only.
Re: Count function not run
For that instead of totocc() you would use count with the where clause to get the number of eligible individuals and then get a random number between 1 and the number of eligible individuals. The tricky part then is that you have to figure out the index in the repeating form of the individual you picked. For example say you have the following data:
In that case count will you give you 3 so you will get a random number between 1 and 3. Say you get 2. Now you want to get the name of the second eligible person which is Bob. You can't use the random to get that directly since the name of the second overall person is Mary who is not eligible. To get the name of eligible person number 2 you can use the seek function to look for only eligible people and pass it @2 to get the second instance that matches the condition. The code would look something like:
In practice you would also need to handle the case where numEligible is zero.
Code: Select all
Q902BB Q902B
-------- -------
John 1
Mary 0
Bill 0
Bob 1
Linda 0
Frank 1
Code: Select all
numeric numEligible = count(SECTION_9A_FORM where Q902B = 1);
numeric pick = random(1, numEligible);
numeric pickedIndex= seek(Q902B = 1, @pick);
NAME = Q902BB(pickedIndex);