Count function not run

Discussions about CSEntry
Post Reply
ramesh2015

Count function not run

Post by ramesh2015 »

Dear Sir,

I am using single variable in rotation roster. And count how many male member in this table.


Thanks
Ramesh
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Count function not run

Post by josh »

I don't understand your question. What exactly is the problem?
rameshpal99
Posts: 8
Joined: January 10th, 2014, 5:57 am

Re: Count function not run

Post by rameshpal99 »

Dear Sir,

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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Count function not run

Post by josh »

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);
rameshpal99
Posts: 8
Joined: January 10th, 2014, 5:57 am

Re: Count function not run

Post by rameshpal99 »

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.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Count function not run

Post by josh »

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:

Code: Select all

Q902BB         Q902B
--------       -------
John           1
Mary           0
Bill           0
Bob            1
Linda          0
Frank          1
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:

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);
In practice you would also need to handle the case where numEligible is zero.
Post Reply