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>
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.
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.