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 (January 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Jan 2004 11:43:16 -0500
Reply-To:     diskin.dennis@KENDLE.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dennis Diskin <diskin.dennis@KENDLE.COM>
Subject:      Re: Interleaving Observations
Comments: To:
Content-Type: text/plain; charset="us-ascii"


One cumbersome solution requires renaming variables using dataset options. If there are many variables, this could be automated via a macro. Also the macro could automate retaining formats and labels, if any.

data xy; set x(in=in_x rename=(x=_x)) y(in=in_y rename=(y=_y)) ; by recno; retain x y; drop _:; if in_x then x = _x; if in_y then y = _y; run;

HTH, Dennis Diskin

Kevin Myers <kevinmyers@AUSTIN.RR.COM> Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> 01/28/2004 11:28 AM Please respond to kevinmyers

To: SAS-L@LISTSERV.UGA.EDU cc: Subject: Re: Interleaving Observations

P.S. - The recno values won't necessarily be contiguous nor start at one. Both data sets are sorted by recno, and there will be no duplicate values of recno in the two data sets.

----- Original Message ----- From: "Kevin Myers" <kevinmyers@AUSTIN.RR.COM> Newsgroups: To: <SAS-L@LISTSERV.UGA.EDU> Sent: Wednesday, January 28, 2004 10:19 AM Subject: Interleaving Observations

> Howdy folks, > > Have two data sets with one common variable that records from the two data sets need to be interleaved by, plus lots of additional variables that *differ* between the two data sets. Conceptually what I want to do is illustrated by the following examples: > > data x; > recno=1; x=1; output; > recno=4; x=4; output; > run; > > data y; > recno=2; y=2; output; > recno=3; y=3; output; > recno=5; y=5; output; > run; > > /* neither of the following steps do what I need, but both are sorta close in different ways */ > > /* ignores BY statement, fails to interleave records in desired order, quits when first data set runs out of records */ > data _null_; set x; set y; by recno; put recno= x= y=; run; > > /* interleaves records in desired order, but fails to retain values */ > data _null_; retain _all_; set x y; by recno; put recno= x= y=; run; > > /* desired output */ > recno=1 x=1 y=. > recno=2 x=1 y=2 > recno=3 x=1 y=3 > recno=4 x=4 y=3 > recno=5 x=4 y=5 > > Conceivably I could achieve the desired result using a very inefficient SQL join, but I'm actually working with *lots* of data, and need a more efficient solution. Also, I have thought of several multi-step solutions, but all seemed ugly and unnecessarily complex. I'd strongly prefer a simple and elegant solution, as what I'm really trying to accomplish here is to replace and greatly simplify some very complicated existing code. > > Thanks in advance, > s/KAM >

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