Help using Base SAS procedures

How to combine two datasets by variable name?

Reply
Contributor
Posts: 57

How to combine two datasets by variable name?

I have two sas datasets which looks as below

 

1.

id A B C D E

 

2.

id B A C E D 

 

How can I combine these two datasets, here my variables are not in same as you can see above. 

 

I would like to combine these two into one datset. 

Super User
Posts: 7,827

Re: How to combine two datasets by variable name?

Posted in reply to mantubiradar19

As long as the columns have the same names, their order in the dataset is irrelevant.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,976

Re: How to combine two datasets by variable name?

Posted in reply to mantubiradar19

Irrespective of position, when the PDV executes, it creates in memory one variable for each one found in the contributing tables, if the same appears twice then you will get errors.  There are several methods to get what you want, but they all require some sort of renaming or re-populating to variables with a different name.  So say A is your linking variable you could do:

data want;
  set have1 have2 (rename=(b=b1 c=c1 d=d1 e=e1));
  by a;
run;
Contributor
Posts: 57

Re: How to combine two datasets by variable name?

Thank you very much RW9! Let me try this!
Contributor
Posts: 57

Re: How to combine two datasets by variable name?

What is my variable name is like ABC123? 

Super User
Posts: 7,827

Re: How to combine two datasets by variable name?

Posted in reply to mantubiradar19

You can rename to any valid SAS variable name

- maximum of 32 characters

- must start with a letter or underline

- can contain letters, underlines and numbers

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 57

Re: How to combine two datasets by variable name?

Posted in reply to KurtBremser
Got it KurtBremser! Thanks a lot
Contributor
Posts: 57

Re: How to combine two datasets by variable name?

I run this code and I get a dataset with observations of dataset1 and 2 combined and also I have variable columns combined!
Ask a Question
Discussion stats
  • 7 replies
  • 289 views
  • 0 likes
  • 3 in conversation