Date: Sat, 11 Oct 1997 02:36:34 GMT
Reply-To: LPogoda <lpogoda@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: LPogoda <lpogoda@AOL.COM>
Organization: AOL http://www.aol.com
Subject: Re: Merge and interleave simultaneously?
In article <19971010164601.MAA20097@ladder02.news.aol.com>,
dnordlund@aol.com (DNordlund) writes:
>More than one peerson has suggested using a three-way merge for the above
>problem, but this will not accomplish what the original poster wanted.
>
>For a given OCC, the above merge statement will take the first record from
>perm.MEN (for that OCC), the first record from perm.WOMEN (for that OCC),
>and the record from perm.OCC and make a single record. Then the same would
>occur for the second record from each file (for that OCC). The original
>poster wanted to interleave perm.MEN and perm.WOMEN, keeping these records
>separate, then merge in occupation information. The above merge does not
>do this.
So OK, the code was less than complete. The basic idea is sound though.
By way of illustration let's take PERM.MEN to have four variables - NAME,
AGE, SEX, and OCC; PERM.WOMEN also has these four variables, while PERM.OCC
has two - OCC and DESCRIBE. The code would look something like:
proc sort data = perm.men out = men;
by occ;
proc sort data = perm.women out = women;
by occ;
proc sort data = perm.occ out = occ;
by occ;
data interlev (keep = name age sex occ describe);
merge men (in = men
rename = (name = mname age = mage sex = msex))
women (in = women
rename = (name = wname age = wage sex = wsex))
occ (in = occupy);
by occ;
if men and occupy then do;
name = mname;
age = mage;
sex = msex;
output;
end;
if women and occupy then do;
name = wname;
age = wage;
sex = wsex;
output;
end;
run;
Feel free to elaborate as the situation warrants.
|