BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pchen002
Obsidian | Level 7
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

1 ACCEPTED SOLUTION

Accepted Solutions
Norman21
Lapis Lazuli | Level 10

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 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

View solution in original post

6 REPLIES 6
Norman21
Lapis Lazuli | Level 10

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 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

pchen002
Obsidian | Level 7
Thanks!
Astounding
PROC Star

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;

 

 

pchen002
Obsidian | Level 7
Thanks for your reply!
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Norman21
Lapis Lazuli | Level 10

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 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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