Help using Base SAS procedures

How can I join 2 tables and keep the data of columns with the same name?

Reply
Occasional Contributor
Posts: 17

How can I join 2 tables and keep the data of columns with the same name?

Hello. I've a little problem. How can I join 2 tables and keep the data of columns with the same name? The data of 2 tables is different, and i need make a new table with the result.

The name of tables are:

  • Directa
  • Folios

And the same columns of both tables are called "Burks" and "Blartd". The output must be create a new table, with the name "Final".

Thanks in advanced.

Francisco

Contributor
Posts: 33

Re: How can I join 2 tables and keep the data of columns with the same name?

The answer is easy: no.

You can rename the two column in input

data final;

  merge Directa Folios (rename=(Burks=folios_Burks Blartd=folios_Blartd));

  by xxx;

run;

If you append you can.

Occasional Contributor
Posts: 17

Re: How can I join 2 tables and keep the data of columns with the same name?

Hi.Thanks for the answer. I try to explain with more details:

Dataset P1

PositionCodeClass
1AFA
2AGB
3AHC
4AID
5AJE

Dataset P2

PositionCode
6AA
7AB
8AC
9AD
10AE

And I need the new data set call P_New:

PositionCodeClass
1AFA
2AGB
3AHC
4AID
5AJE
6AA
7AB
8AC
9AD
10AE

Thanks in advanced for your help.

Regards,

Francisco

Contributor
Posts: 33

Re: How can I join 2 tables and keep the data of columns with the same name?

It's an append.

Ypu can do with a datastep

data new;

  set pi_1 P_new;

run;

Or with the proc append.

Proc append base=P_1 data=P_new force; run;

The code is written by memory so some error could be in it. Test it and change it.

Frequent Contributor
Posts: 83

Re: How can I join 2 tables and keep the data of columns with the same name?

Or you can just stack them

data final;

     set     Directa

               Folios;

run;

As long as they are in the same positions, ie the data that you had presented earlier this will just stack the two of them on top of each other.

Ask a Question
Discussion stats
  • 4 replies
  • 238 views
  • 2 likes
  • 3 in conversation