SAS : Use of Multiple SET Statements

Deepanshu Bhalla 13 Comments

In SAS, you can perform one-to-one reading with the help of multiple SET statements. It combines observations from two or more data sets into a single observation in a new data set.

Suppose you have two very big datasets. You have IDs column in both the datasets. Each ID in the first dataset has a matching ID in the second one and they are in the same order. Your task is to merge these datasets but the usual method of data step merging doesn't work because it uses a lot of memory. Instead you can use the MULTIPLE SET Statements for merging them.

DATA dat1;
INPUT id v1 v2;
CARDS;
1 10 100
2 15 150
3 20 200
;

DATA dat2;
INPUT id v3 v4;
CARDS;
1 1000 10000
2 1500 15000
3 2000 20000
4 800 30000
;
RUN;
DATA dat3;
set dat1;
set dat2;
RUN;
SAS : Multiple SET Statements
The observations are combined based on their relative position in the data set.
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

13 Responses to "SAS : Use of Multiple SET Statements"
  1. The output will turn out to be different if:
    DATA dat3;

    set dat1 dat2;

    RUN;

    ReplyDelete
    Replies
    1. in this case datasets will append

      Delete
  2. inthis multiple set statement dat2 override dat1.

    ReplyDelete
    Replies
    1. yes... same thing this will only happen when we set dat1 dat2;

      Delete
  3. this website is really very helpful

    ReplyDelete
  4. DATA dat3;
    set dat1;
    set dat2;
    RUN;

    dat3 will be minimum of dat1 and dat2
    what if i want maximum number of row in dat1 nd dat2

    ReplyDelete
    Replies
    1. Use Merge without BY
      DATA dat3;
      Merge dat1 dat2;
      run;

      Delete
  5. It will append data set ....i think ..how it can merge data set

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. What will output when we used set dat1 dat2

      Delete
    2. hi ,

      the output will be like,
      dat 2 observation, kit will omit the dat1,
      when we use
      set dat1 dat2;
      run;

      Delete
  7. So, it should be like......

    data new3;
    set new1;
    set new2;
    /* merge new1 new2; */
    run;
    proc print data=new3;
    run;

    ReplyDelete
Next → ← Prev