Help Needed: Extracting 18+ Members’ Names from Household Roster
Posted: November 6th, 2025, 1:19 pm
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
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