Help using Base SAS procedures

How to merge files with similar names in the same library

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

How to merge files with similar names in the same library

I have many files in the work library with the names as data01, data02, data03, ... data50.  All these dataset have the same contents, with one variable as the key.

My question is how can I merge all these files easily? I tried to do it using : as below, but failed.

data work.data;

     merge data: ;

run;

Many thanks.


Accepted Solutions
Solution
‎11-21-2011 12:57 PM
Super User
Super User
Posts: 6,502

How to merge files with similar names in the same library

Did you get an error message or just not get the expected results? 

Are you running at least version 9.2?

Works for me.

data data01 data02;

  set sashelp.class;

run;

 

data data;

  merge data:;

  by name;

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,300

How to merge files with similar names in the same library

If they all have the same contents it sounds more like you want to set them together rather than merge them.

Frequent Contributor
Posts: 131

How to merge files with similar names in the same library

Sorry the datasets are different. So it is definitely a merge. The datasets have one same variable.

Solution
‎11-21-2011 12:57 PM
Super User
Super User
Posts: 6,502

How to merge files with similar names in the same library

Did you get an error message or just not get the expected results? 

Are you running at least version 9.2?

Works for me.

data data01 data02;

  set sashelp.class;

run;

 

data data;

  merge data:;

  by name;

run;

Frequent Contributor
Posts: 131

How to merge files with similar names in the same library

Thanks, Tom. I just got it right. Basially, the values in the key variable are: pctile1, pctile2, ... pctile10, pctile11, So the values are not sorted, thought it looks like they are Smiley Happy Sorry and thanks!

Contributor
Posts: 65

How to merge files with similar names in the same library

Hi,

Even it worked for me! Here's what I have:

data data01;

input key col1;

cards;

1 101

2 102

3 103

4 104

5 105

;

run;

data data02;

input key col1;

cards;

1 101 <-- This col is same as previous dataset

6 102

7 103

8 104

9 105

;

run;

data want;

merge data01 data02;

by key;

run;

Result Set:

Key Col1

1     101

2     102

3     103

4     104

5     105

6     102

7     103

8     104

9     105

Do you have the same column name in all the tables? If possible provide example of what you have.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 159 views
  • 0 likes
  • 4 in conversation