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

I have merged two data sets by a variable called "ID." However, both data sets that I merged contained the variable "Street." After I merged the two data sets, only the first dataset's Street variable column remained. How can I keep both of the variable Street data in separate columns without overriding one of them? The given data is also from excel files so I cannot easily change the name before importing the data. If there is a code for me to change the name of a given variable, please state. Thank you so much!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Rename the variable in one of the data sets. You can do that in the merge, you don't say how you merge but it can be done in either a SQL or data step merge.

 

merge data1 data2(rename=(street=d2_street));

@Ramsha wrote:

I have merged two data sets by a variable called "ID." However, both data sets that I merged contained the variable "Street." After I merged the two data sets, only the first dataset's Street variable column remained. How can I keep both of the variable Street data in separate columns without overriding one of them? The given data is also from excel files so I cannot easily change the name before importing the data. If there is a code for me to change the name of a given variable, please state. Thank you so much!

 


 

View solution in original post

3 REPLIES 3
error_prone
Barite | Level 11
You can rename variables in the merge statement. And there should be an example in the docs of merge statement.

Example (untested)
merge data_a data_b(rename=(street=street_b));
by I'd;

Reeza
Super User

Rename the variable in one of the data sets. You can do that in the merge, you don't say how you merge but it can be done in either a SQL or data step merge.

 

merge data1 data2(rename=(street=d2_street));

@Ramsha wrote:

I have merged two data sets by a variable called "ID." However, both data sets that I merged contained the variable "Street." After I merged the two data sets, only the first dataset's Street variable column remained. How can I keep both of the variable Street data in separate columns without overriding one of them? The given data is also from excel files so I cannot easily change the name before importing the data. If there is a code for me to change the name of a given variable, please state. Thank you so much!

 


 

ballardw
Super User

It would help to show the code used to merge the data so we could reference data sets and actual variable names.

If you used a data step merge then you can use a data set option on one set to change the name:

 

data want;

   merge dataone

              datatwo (rename=(street = streetwo))

   ;

   <other code>

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1053 views
  • 3 likes
  • 4 in conversation