|
|
|
||||
|
Help the Stat Consulting Group by
giving a gift
| |||||
|
Loading
|
|||||
The example below takes data with numerous records from a single household, with a variable hh indicating head of household (0=head) and matches that person with a corresponding spouse (hh=1 or 2). It saves the sex and ethnicity, and identifies mixed marriages.
data all;
input hid hh anything eth sex;
cards;
1 0 1 1 1
2 0 2 1 2
2 9 3 2 1
3 0 4 2 1
3 1 5 2 2
3 9 6 1 1
4 0 7 3 2
4 9 8 5 1
5 0 9 2 2
5 2 10 6 1
5 9 11 4 1
;
run;
proc sort data=all;
by hid;
run;
data hh;
set all(rename= (eth=hheth sex=hhsex) );
if hh = 0 then output;
run;
data spouse;
set all(rename= (eth=speth sex=spsex) );
if hh = 1 or hh = 2 then output;
run;
data married;
merge spouse(in=tspouse) hh(in=thh) ;
by hid;
hh = thh;
spouse = tspouse;
if speth = . then mixed = .;
else if hheth EQ speth then mixed = 0;
else mixed = 1;
run;
proc freq data=married;
tables hh*spouse;
run;
proc print data=married;
run;
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services