Dear all,
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:
PROC SQL;
CREATE TABLE TEST AS
SELECT A.*, B.*
FROM A
LEFT JOIN B
ON A.STATE=B.STATE AND A.FYEAR=B.FYEAR;
QUIT;
Hope anyone give me a solution.
Thank you.
MSPAK
Post your log and please explain what you mean by failed.
There is no error message, but the following note is found:
NOTE: Table WORK.test created, with 0 rows and 1262 columns.
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.
Result from proc contents
SAS Output
Alphabetic List of Variables and Attributes (DATASET A) | ||||
---|---|---|---|---|
# | Variable | Type | Len | Label |
2 | BankState | Char | 24 | |
4 | FailedBanknum | Num | 8 | |
3 | FailureYr | Num | 8 | |
6 | R5_FailedBank | Num | 8 | Rank for Variable FailedBanknum |
7 | fyear | Num | 8 | |
5 | logFBanknum | Num | 8 | |
1 | state | Char | 8 |
SAS Output
Alphabetic List of Variables and Attributes (DATASET B) | ||||||
---|---|---|---|---|---|---|
# | Variable | Type | Len | Format | Informat | Label |
2 | FYEAR | Num | 8 | F6. | 6. | Data Year - Fiscal |
1 | GVKEY | Char | 6 | $6. | $6. | Global Company Key |
3 | STATE | Char | 8 | $8. | $8. | State/Province |
I get the following:
You should probably think about what columns to select though..
Hi again,
If you open the output, you will notice that the GVKEY variable are all blank. I need the gvkey.
@mspak wrote:
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.
If I used the following code, no row is generaed:
PROC SQL;
CREATE TABLE testAS
SELECT a.*, b.*
FROM B a, A b
WHERE (b.fyear = a.failureyr AND b.state = a.bankSTATE); quit:
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.
Good Luck
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).
I can't see difference on the abrevation between two files. I might just convert it to excel and do it manually.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.