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!
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!
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!
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>
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.