BookmarkSubscribeRSS Feed
OzanKirtac
Fluorite | Level 6

Hi 

 

I am trying to merge two datasets but I seem to be missing something as the data I merge does not look really good. I try to add new variable to existing dataset on the condition that two variables have the same values in two different datasets. I attach partially both datasets. You will see when you merge, all data merges to the same observations. Log is clear so this possibly a coding problem. I did not attach the full datasets but partial datasets for crspmonthly2 and mergedcikedgar. The final output file is attached. I see that a one observation is matched with all the appended variables. Can be it be related with empty date cell in the data?

 

proc sql; create table perm.mergedcikedgar10 as select
a.*, b.gvkey
from perm.Mergedcikedgar as a left join perm.crspmonthly2 as b
on a.Cik=b.CIK
and month(a.date) eq month(b.datadate)
and year(a.date) eq year(b.datadate);
quit;

2 REPLIES 2
ballardw
Super User

Equality for comparisons is very restrictive. So you may need to make sure the values are as you expect in multiple data sets.  "ABC" does not match "Abc" or " ABC" (note leading space). You may need to make your comparison for character values case insensitive, such as UPCASE or LOWCASE both values, or make sure that there are no leading spaces or different numbers of embedded spaces ("A BC" is not equal to "A   BC"), or that other characters separating values such as comma or hyphens are exactly the same in both sets. Also some times depending on your data source characters that look the same such as dash may be a different dash character.

 

Good luck.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 294 views
  • 0 likes
  • 3 in conversation