LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Sep 1998 15:17:13 +0200
Reply-To:     PSX Dude <are.skaar@EUNET.NO>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         PSX Dude <are.skaar@EUNET.NO>
Organization: EUnet Norway
Subject:      Re: variables across obs

Lynn Nicole Lethbridge wrote in message <6shce0$100$1@News.Dal.Ca>... >Hi there > >I have a dataset which has an observation for each member of a household >with each household having it's own unique identifier. The first >observation is considred the 'head'. After that there may or may not be a >spouse and kids. > >I would like to put infomation about the head and spouse (if present) into >the kids observations (if any). For instance, I'd like the head's age in >the kids observations. >

Getting the head age to all observations is done by the following code:

data family2; set family; by hh; retain head_age; if first.hh then head_age=age; run;

If you also want any spouce's age (assuming that the spouce is always the second obs within each group) The following code should do the trick. (Be aware that this code is slow as it reopens and closes the dataset for each group)

data family3(drop=dsid rc); set family; by hh; retain head_age sp_age; if first.hh then do; head_age=age; dsid=open('work.family(where=(hh='||hh||'))','I'); rc=fetch(dsid);*Fetching 1 obs within group (the head); rc=fetch(dsid);* Fetching the second obs within group (the spouse); if rc=0 then sp_age=getvarn(dsid,varnum(dsid,'age'));*Retrieving age if spouse exists; else sp_age=.; dsid=close(dsid); end; run;

Hope this helps


Back to: Top of message | Previous page | Main SAS-L page