Page 1 of 1

Automatically make the system to preselect the 1st options that appear in setvalueset

Posted: July 26th, 2022, 6:44 am
by sham
Hi family,
I have a challenge here.
I created a setvalueset from the a roster using preproc. Is there a way to allow the system to select the 1st option that appear in the setvalueset RESULTS regardless about the value serial numbering?

for example
Below is the logic I used to pull out the list of eligible person's in the household age 15-49years at random
PROC ID_FROM_THE_ROSTER
preproc
do numeric i = 1 while i <= totocc(ROSTER000)
if AGE(i) in 15:149 then
RosterRespondent.add(NAME(i),i);
endif;
enddo;
seed(systime());
RosterRespondent.randomize();
setvalueset($,RosterRespondent);
the results I got is;
option1 3. Child1
option2 5. Child
option1 7. Child5

Can any one assist me with a logic to make the program automatically select the the 1st position(child3) from the setvalueset results above?

Thank you

Re: Automatically make the system to preselect the 1st options that appear in setvalueset

Posted: July 26th, 2022, 9:13 am
by Gregory Martin
You can access the codes and labels as lists:

https://www.csprousers.org/help/CSPro/valueset.html

So this would give you the first code (if one has been defined):
RosterRespondent.codes(1)

Re: Automatically make the system to preselect the 1st options that appear in setvalueset

Posted: July 26th, 2022, 10:42 am
by sherrell
Sham, I hope you've noticed the typo in your logic. You wrote the following comment:

>Below is the logic I used to pull out the list of eligible person's in the household age 15-49years at random

Yet your logic is checking to 149 years:

>if AGE(i) in 15:149 then

Sherrell

Re: Automatically make the system to preselect the 1st options that appear in setvalueset

Posted: July 26th, 2022, 11:00 pm
by sham
Hi,
@Sherrell you got it right it is indeed a typo from me. I actually mean 15-49.
@ Gregory Martin thank you very much for the guide.

It is working soo well.

I Am grateful.