BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bncoxuk
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
FriedEgg
SAS Employee

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

bncoxuk
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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;

bncoxuk
Obsidian | Level 7

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!

Pritish
Quartz | Level 8

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2559 views
  • 0 likes
  • 4 in conversation