BookmarkSubscribeRSS Feed
Maisha_Huq
Quartz | Level 8

Hello!

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?

Thoughts?

I appreciate the feedback!

Happy holidays

2 REPLIES 2
Patrick
Opal | Level 21

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

Reeza
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 458 views
  • 0 likes
  • 3 in conversation