Help Needed: Extracting 18+ Members’ Names from Household Roster

Discussions about CSEntry
Post Reply
prabhustat
Posts: 77
Joined: March 17th, 2012, 10:46 am

Help Needed: Extracting 18+ Members’ Names from Household Roster

Post by prabhustat »

Hi Team,

I need some help with a CSPro logic issue. I want to extract from the household roster the names of members aged 18 years and above and store those names as values in a single-response or multiple-response variable (note: this variable is not part of the roster).

I’ve added a script for this, but it’s not working as expected. Can anyone please take a look and help me figure out what’s going wrong?

function valueset MakeRoster18PlusValueSet(numeric excludeOcc = 0)
valueset vs18; // <-- changed from "valueset vs"
numeric idx;

do idx = 1 while idx <= count(PERSON_REC)
// Skip blank names
if strip(B2A(idx)) = "" then
next;
endif;

// Only include members aged 18 or above
if not defined(B2C(idx)) or B2C(idx) < 18 then
next;
endif;

// Optionally exclude a specific occurrence
if excludeOcc > 0 and idx = excludeOcc then
next;
endif;

// Add to the list: Label = name, Code = occurrence number
vs18.add(B2A(idx), idx);
enddo;

// Optional: alphabetical sort by label
// vs18.sort("label");

MakeRoster18PlusValueSet = vs18; // Return the value set
end;


PROC F24
preproc
valueset v = MakeRoster18PlusValueSet();
setvalueset(F24, v);

Thanks in advance!
— Prabhu
Arjun Brti
Posts: 63
Joined: October 15th, 2020, 3:40 am
Location: Nepal

Re: Help Needed: Extracting 18+ Members’ Names from Household Roster

Post by Arjun Brti »

Hi prabhustat,
You can use the logic somthing like this:

// For single response (numeric variable)

PROC F24
onfocus
valueset Age18_Above;
Age18_Above.clear();
do numeric counter = 1 while counter <= count(PERSON_REC)
if Age(counter) >= 18 then
Age18_Above.add(Name(counter),PersonIdCodeonRoster(counter));
else
endif;
enddo;

setvalueset($, Age18_Above);

For multiple response, you should change the PersonIdCodeonRoster and F24 both variable as string and use the string valueset too.
prabhustat
Posts: 77
Joined: March 17th, 2012, 10:46 am

Re: Help Needed: Extracting 18+ Members’ Names from Household Roster

Post by prabhustat »

Thanks Arjun
Post Reply