BookmarkSubscribeRSS Feed
Songchan
Calcite | Level 5

Hello Guys,

 

I'm trying to merge two tables by cusip number and date, there are no empty values in every column, but the merged table has empty columns, what are the possible reasons?

 

Thank YOU

proc sql; 
     create table aa
	 as select a.*, b.*
	 from temp04 as a
	 left join temp05 as b
	 on a.cusip=b.cusip and a.datadate=b.date;
quit;

Capture.PNGCapture2.PNGCapture3.PNG

6 REPLIES 6
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
proc sql; 
     create table aa
	 as select a.*, b.*
	 from temp04 as a,
	 temp05 as b
	 where a.cusip=b.cusip and a.datadate=b.date;
quit;
Songchan
Calcite | Level 5

Thank you for your reply, but i need temp04 left join temp05.

Astounding
PROC Star

With a left join, this just means there are some mismatches ... CUSIPs and/or dates that appear in temp04 but don't appear in temp05. 

 

Inspecting the data you posted, it looks like there would be plenty of mismatches.  The result you have is not surprising.  You need an exact match on both CUSIP and DATE.

Songchan
Calcite | Level 5

Yes, because i only need the data in temp04, temp05 is all 20-year daily data. My result shows the whole column is empty

ballardw
Super User

When you have two tables with the same variable name and you use Select a.*, b.* the value of the common named variable may not be coming from the table you expect.

Try using this select and see if it helps:

 

Select a.cusip as cusipA, b.cusip as cusipB, a.*, b.*

PGStats
Opal | Level 21

Is the format for CUSIPs the same in both datasets? It seems to have 9 characters with leading zeros in temp04 and 8 characters without leading zeros in temp05.

PG

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 4884 views
  • 1 like
  • 5 in conversation