Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Reply
Occasional Contributor
Posts: 12

Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Hello this is my 2nd/4 questions:

I am trying to understand the named question above. I am posting it below for convenience:

Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?


I am expected to format my answers by including the following:



a) find out, for each issue, between 3 and 5 interesting documentation sources (eg SAS User's manuals, SAS course notes, archives of the SAS-L list, forums like SAS communities, SUGI papers, blogs on SAS, courses offered on university sites,...) explaining how to deal efficiently with this issue

b) for each issue, give all the possible answers, explaining their relative characteristics and advantages, indicating the sources where the information was found.

c) for each issue, the final synthesis should be very clear, proofread and potentially useful for people looking for explanations about the way to deal with the data management issues at stake, using SAS. It implies that, for each issue, the assignment should start with a brief explanation of what the issue is, then explain how to deal with this issue, and end with at least two short examples (easy to understand and to replicate) with comments between /* */.

I appreciate comprehensive help, as these answers will enable better understanding and better performance on my upcoming exam.

Kind regards!

Super User
Posts: 19,192

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

So what's your question? How to interpret the question?

Occasional Contributor
Posts: 12

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Hello again, Reeza. Yes, how to interpret the question and how to best and most efficiently perform the task, including the "when is it necessary" part of the question. If you have an interesting sources for answers to questions like the ones I have posted, that too would be very helpful.

Occasional Contributor
Posts: 12

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Hi Shelley- I think this is the second message you have copied- I am confused! Is there a better way I should address Reeze?

Community Manager
Posts: 400

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

No, you're doing everything correctly. Because there are multiple questions and replies, I am moderating them as they come in. Things may look a little out of whack until everything gets approved for posting. Just keep going, we'll get your questions/replies out as quickly as possible.

Thanks,

Shelley

SAS Online Community Manager

Super User
Posts: 19,192

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Search LexJansen.com - there a many many papers on most of these topics with various solutions but you'll have to aggregate them together to get what you want.

Occasional Contributor
Posts: 12

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Thank you!

Frequent Contributor
Posts: 130

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Renaming your variables are necessary when the variables will be used in a data step merge and will be the variables being merged on in the BY statement.  Otherwise, you'll have to use a SQL Procedure to merge the two data sets (doesn't require the variable being merged on to have same name).  You can rename the variable(s) in your merge statement of the data step merge by using the (rename=(newvar=oldvar)).  Data step merges require that the variables you are merging the two data sets on have the same format and name and are sorted by that variable before merging.

data want;

merge have1 (rename=(empid=ID))

have2;

by ID;

run;

Occasional Contributor
Posts: 12

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Thank you dcruik. I appreciate this very much. Where can I look for more examples? For example, like an annotated output? Or syntax with comments explaining the steps?

Frequent Contributor
Posts: 130

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

I would highly recommend getting onto the SAS Support website and looking around there for a lot of good syntax and examples of questions you may have, as they have a great support website that I use often when researching issues and techniques to use (I would just use the search bar at the following website and there are tons of documentation with syntax and examples explainig different procedures and techniques): https://support.sas.com/

Many times just googling issues and different thins in SAS will take you to the support.sas.com URL.

This would be a useful source for your data merging and introducing how to use it and the basics:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001304305.htm

Occasional Contributor
Posts: 12

Re: Renaming (in SAS) some variables of 2 datasets before horizontally merging them. When is it necessary? How to do that within the merging data step itself?

Thank you so much!

Ask a Question
Discussion stats
  • 10 replies
  • 304 views
  • 0 likes
  • 4 in conversation