Call Rantbl Question

Frequent Contributor
Posts: 131

Call Rantbl Question


I have a data set on participants and participants' children; the data set is not one record per child.

For example, the input data set includes

part_ID  part_hh_type  child_name1, child_dob1, child_name2, child_dob2, child_name3, child_dob3 

...for 10 children.

I want the output data set to look like (blue are new vars):

part_ID  part_hh_type  child_name1, child_dob1, child_name2, child_dob2, child_name3, child_dob3... pick_childname,  pick_childdob

I want the two new vars pick_childname and pick_childdob to be the name and DOB for a child that the program will choose for the participant so that the overall sample ends up having a particular proportion of children in the three grade ranges pre-k, middle school, and high school. 

The var part_hh_type is the concatentation of the participant's number of children in the three grade ranges prek, middle, and highschool.

For example, hh_type "201"  means the participant has two children in prek, zero in middle school, and one child in high school. 

There are 26 hh_types.  For each hh_type, I have vars p1, p2, and p3 which is the percent of all those hh_type participants whose "chosen" kid will be from grade ranges prek, middle, and high schoo, respectively.

For exampleo, for all the participants who have 201 hh_type and p1=.5, p2=.5, p3=0,  the sample should pick a kid from the pre-k age range for 50% of the participants and a kid from the middle school grade range for the other 50% of the participants; no participants with hh_Type 201 will have their hs kid chosen.

Once the age range of the s_childname is chosen, the program will randomly select one of the kids in that age range to be the pick_childname and pick_childdob.

I am using the call rantbl function to select the age range of the kid and then call ranuni to select the kid from that age range randomly.

But how do I use this for ALL 26 hh_types?


I appreciate the feedback!

Happy holidays

Respected Advisor
Posts: 4,132

Re: Call Rantbl Question

Please provide some sample data (a data step creating a SAS table).

The "hh_type" variable tells us how many children there are and how they are distributed over the grade ranges. How do we know which child belongs into which grade? Is this just based on age? Or if you have a hh_type=201 would the 2 pre-k children be in "child_name1 & child_name2" and the high school child would be in "child_name3"?

As a general approach:

I would transpose the wide structure of your source data into a long structure and then try and have Proc Surveyselect do the job for me SAS/STAT(R) 9.3 User's Guide

Super User
Posts: 19,105

Re: Call Rantbl Question

This would be much easier using proc survey select and transposing your data.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation