Page 1 of 1

Randomly Select 5 Cases from a dynamic valueset

Posted: March 30th, 2020, 5:30 pm
by Yass
Hi CSPro Team,

I would like tp restrict the number of dynamic value set to 5 from set of eligible cases, I have a listing of HHs that I want to dynamically
show 5 eligible cases out of the many from a lookup in a menu program.

Code: Select all

onfocus

valueset hhVS;

forcase  DVV_DICT where SELECT_CLUSTER=HCLUSTER  and  age  > 18 do
      //   if …..endif                            //Random selection of 5  cases 
   
   hhVS.add(maketext(HHEAD) +  " - "  + strip(ADDRESS),HHNO);

endfor;
setvalueset(SELECTED_HH, hhVS);

Please is it possible to restrict the number of HHs in the codes above or there is a better way to do it. Thanks for the support always.

Re: Randomly Select 5 Cases from a dynamic valueset

Posted: April 9th, 2020, 8:23 am
by Gregory Martin
One thing you could do is add all of the eligible households to the value set and then do:
randomizevs(hhVS);
Then you could look at the first 5 entries in that value set. However, what's important with randomization is that you remember the settings from one run to the next. Once you've selected the five households, you may want to save those selections somewhere so that you don't get a different set of random households the next time you run your program.

Re: Randomly Select 5 Cases from a dynamic valueset

Posted: April 9th, 2020, 2:39 pm
by Yass
Thanks Greg, Please can you help me with the line of codes in selecting the first 5 cases.

Thanks

Re: Randomly Select 5 Cases from a dynamic valueset

Posted: April 9th, 2020, 6:41 pm
by Gregory Martin
This loops through the first 5 (or fewer if there aren't 5) entries:
do numeric counter = 1 while counter <= low(5, hhVS.length())
    // do something with hhVS.codes(counter)
enddo;

Re: Randomly Select 5 Cases from a dynamic valueset

Posted: April 9th, 2020, 8:44 pm
by Yass
Thanks Greg !!