11-20-2016 09:22 AM
I have 2 files:
A and B (attached).
I would like to merge the data by state and fyear. However, it is unknow why it failed. I used the following code:
CREATE TABLE TEST AS
SELECT A.*, B.*
LEFT JOIN B
ON A.STATE=B.STATE AND A.FYEAR=B.FYEAR;
Hope anyone give me a solution.
11-20-2016 09:36 AM
Check that the variables you're merging on have same type and formats - use PROC contents.
Run a proc freq on each of the variables and look for inconsistencies.
Post the log and whatever results you can.
11-20-2016 09:40 AM
Result from proc contents
|Alphabetic List of Variables and Attributes (DATASET A)|
|6||R5_FailedBank||Num||8||Rank for Variable FailedBanknum|
|Alphabetic List of Variables and Attributes (DATASET B)|
|2||FYEAR||Num||8||F6.||6.||Data Year - Fiscal|
|1||GVKEY||Char||6||$6.||$6.||Global Company Key|
11-20-2016 09:51 AM
There is no error message, but the following note is found:
NOTE: Table WORK.test created, with 0 rows and 1262 columns.
How is GVKEY blank if there's no rows. I feel like we're missing something.
11-20-2016 09:59 AM
If I used the following code, no row is generaed:
CREATE TABLE testAS
SELECT a.*, b.*
FROM B a, A b
WHERE (b.fyear = a.failureyr AND b.state = a.bankSTATE); quit:
11-20-2016 10:34 AM
So you posted code in your original question and then the note from different code?
Most likely your state state aren't matching for some reason.
Verify visually with a proc freq. Are the spellings and case exactly the same?
Trim/Compress the variables to remove any possible invisible characters and try your merge again.
PS Many can't/won't download zip files due to IT restrictions and viruses.
11-20-2016 06:02 PM
You get zero rows because your where clause is never true.
You should not use the * wildcard in the select statement like you do if there can be same named columns coming from both source tables.
And just as an observation:
Your State variable has a length of 8, your bankState variable has a length of 24. Looks to me as if these two variables contain likely different information (eg. codes or abbreviations vs full names). Also casing will be important (use an upcase() function if you can't be sure that casing matches).