DATA Step, Macro, Functions and more

interleaving

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

interleaving

data brothers.three;
set brothers.one;
set brothers.two;
run;

 

After researching, still don't quite understand why var X in Brother Three is only 2 & 4 and data 5,Karl is gone as well, new to SAS, please help!thanks


Accepted Solutions
Solution
‎09-30-2017 10:49 PM
Frequent Contributor
Posts: 103

Re: interleaving

[ Edited ]

One way to look at this:

 

The values in the first data set are "replaced" by the values in the second data set (if they exist).

 

So, all the VarX in the first data set have been replaced by all the VarX in the second data set.

 

All the VarY have made it to the end, as there are no VarY in the second data set.

 

Similarly, the VarZ appear in the final data set, as there is nothing to replace them.

Norman.
SAS 9.4 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

View solution in original post


All Replies
Solution
‎09-30-2017 10:49 PM
Frequent Contributor
Posts: 103

Re: interleaving

[ Edited ]

One way to look at this:

 

The values in the first data set are "replaced" by the values in the second data set (if they exist).

 

So, all the VarX in the first data set have been replaced by all the VarX in the second data set.

 

All the VarY have made it to the end, as there are no VarY in the second data set.

 

Similarly, the VarZ appear in the final data set, as there is nothing to replace them.

Norman.
SAS 9.4 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

Contributor
Posts: 31

Re: interleaving

Thanks!
Super User
Posts: 6,934

Re: interleaving

[ Edited ]

This program does not interleave anything, since it is missing this statement:

 

by VarX;

 

Try adding it and examine the results.

 

Then turn the two SET statements into a single statement (the normal way to interleave) and examine the results:

 

data brothers.three;

set brothers.one brothers.two;

by varX;

run;

 

 

Contributor
Posts: 31

Re: interleaving

Posted in reply to Astounding
Thanks for your reply!
Trusted Advisor
Posts: 1,394

Re: interleaving

[ Edited ]

Two SET statements means 2 parallel streams of data.  When any SET reaches beyond end of its data step, the data step stops. so the result is no longer than the shorter incoming data set.

 

MERGE (without an associated  BY statement) on the other hand, wlll not stop the data step until the longer incoming is exhausted.  So

    data want;

      merge brothers.three brothers.two;

    run;

 

would yield three observations.

 

If you use   SET one two; by varx;,  then you will get interleaved datasets, because it's a single multi-component stream.

Frequent Contributor
Posts: 103

Re: interleaving

Actually, the program written by pchen002 could be described as one-to-one reading:

 

"One-to-one reading combines observations from two or more SAS data sets by creating observations that contain all of the variables from each contributing data set. Observations are combined based on their relative position in each data set, that is, the first observation in one data set with the first in the other, and so on. The DATA step stops after it has read the last observation from the smallest data set."

 

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p15jvywi5avt3cn1bee8r6c33ux1.htm&docsetVer...

 

Norman.
SAS 9.4 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 362 views
  • 4 likes
  • 4 in conversation