DATA Step, Macro, Functions and more

Merging datasets without using MERGE statement

Reply
New Contributor
Posts: 2

Merging datasets without using MERGE statement

Is there any method to merge two datasets without using MERGE statement . it might be simple question . but as I am new to SAS , Please provide the information . thanks!!

Occasional Contributor
Posts: 14

Merging datasets without using MERGE statement

Posted in reply to kaushiklu

Friend,

Use proc sql using inner join instead of merge statement...

Ankit

PROC Star
Posts: 7,492

Re: Merging datasets without using MERGE statement

Posted in reply to kaushiklu

Depends on what you are trying to do.  Does the following approximate what you are calling merging?

data one;

  input x;

  cards;

1

2

3

;

data two;

  input y $;

  cards;

a

b

c

;

data both;

  set one;

  set two;

run;

HTH,

Art

Contributor
Posts: 28

Re: Merging datasets without using MERGE statement

Posted in reply to kaushiklu

Hi, You can use the proc sql statement to join your two tables.

the inner join is the match join. You'll need your id in the two tables to have it as output.

the left or right join permitts to join a source table with an other and one of the tables is used as reference.

the full join just tries to match your two tables. it's the less used.

Valued Guide
Posts: 2,177

Merging datasets without using MERGE statement

Posted in reply to kaushiklu

when you want to merge data, and since MERGE is obvious, why would you resist using it ? ^

Frequent Contributor
Posts: 75

Re: Merging datasets without using MERGE statement

Hi,

There are lot of methods available for merging 2 datasets. But which method you use is based on the type of data and number of observation it has.

1. PROC SQL;

     SELECT VAR1,VAR2,T1.VAR3,VAR4,VAR5

        FROM TABLE1 AS T1,TABLE2 AS T2

        WHERE T1.VAR3=T2.VAR1;

  QUIT;

In PROC SQL itself there are many methods available (Inner Join, Left Join, Right Join) and apart from that you can use SET operators (EXCEPT,INTERCEPT, UNION) to merge datasets. (But each one serve different purpose).

2. SET statement

a)     DATA dataset-name;

       SET sas-dataset;

       SET sas-dataset;

    RUN;

b)    DATA dataset-name;

      SET sas-dataset;

      SET sas-dataset KEY=index-name;

    RUN;

When you specify the index name in the KEY=option, processing changes from sequential to direct access, and SAS reads only the observation that satisfies the lookup.

Hope this answers your question.

Thanks

Dhanasekaran R

Ask a Question
Discussion stats
  • 5 replies
  • 212 views
  • 0 likes
  • 6 in conversation