BookmarkSubscribeRSS Feed
alexben
Fluorite | Level 6

Hi everyone,

I'm having trouble with a data step merge in SAS. Specifically, when I merge two datasets using the MERGE statement, I get unexpected results. The merge key seems correct, but the output isn’t as expected.

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Please show us your code and describe how your result is different from your expectations. 

PaigeMiller
Diamond | Level 26

In addition to what @PeterClemmensen , show us (a portion of) your data so we can see what you are seeing. Please provide the data as working SAS data step code (examples and instructions) and NOT as a file attachment.

--
Paige Miller
ballardw
Super User

Did you read the log? Some of the common "issues" with Merge create specific messages in the log.

At least describe the unexpected results, we can't read your mind.

 

Or was this post just an excuse to post an advertising link or whatever that dollartree thing is?

 

MERGE in SAS, especially in a data step, has a very specific meaning and some people use the term "merge" without much detail of what is expected. Merge is a sort of side-by-side combination, typically using one or more variables to match records, to bring variables from multiple sets together.

Limitations on the SAS Merge include but are not limited to:

Only one data set can have multiple observations with the same values of BY variables and get expected results.

Variables with same names that are not used for matching on a BY statement will have only one variable with a value similar to updating data. There are some complexities involved.

Minor differences of values such as leading space " John" vs "John", or case "John" "JohN" are not equal and records won't match.

 

And sometimes people want to APPEND data, stack vertically, but use MERGE because of not being familiar with the difference in SAS.

 

So code of what was attempted and a clear description of what was expected are important to answer this sort of question. Example data is the best way to provide start data,  expected and actual results.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 703 views
  • 0 likes
  • 4 in conversation