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>

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 3 replies
  • 283 views
  • 3 likes
  • 4 in conversation