Help using Base SAS procedures

Why cannot I merge these two tables?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Why cannot I merge these two tables?

Hi SAS Forum,

I have been trying to merge the attahced two tables for hours using the follwoing code but didn't work.

Book1 dataset is having a single record which is not taken into the final mereged file called "COMBINED_file" despite the fact its bank_number and account_number

are identically found in book2 talbe as well.

Could any help me?

Thanks

Mirisage

proc sort data=A.BOOK1 out=file_A;

   by bank_number Account_number ;

run;

proc sort data=A.BOOK2  Out=file_B;

     by bank_number account_number ;

run;

data COMBINED_file;

  merge file_A (IN=a)

        file_B (IN=b)

           ;

by bank_number account_number ;

if a and b;

run;

Attachment
Attachment

Accepted Solutions
Solution
‎09-16-2012 02:51 PM
Contributor
Posts: 21

Re: Why cannot I merge these two tables?

data COMBINED_file;

  set file_B

      file_A

       

           ;

by bank_number account_number ;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Why cannot I merge these two tables?

I am not sure if I understand what you are after. You code behaved the way it should. If you want to stack them, then use 'set' to replace 'merge', or if you don't want the variable from file_a being replace by file_b, then switch their order in the merge statement:

merge file_b(in=b) file_a(in=a);

or rename the variable names.

HTH,

Haikuo

Super Contributor
Posts: 338

Re: Why cannot I merge these two tables?

Hi Haikuo,

Thanks.

Sorry for the confusion.

The final merged table that I want should look like below table. It should comprise all 5 records of Book2 data set and the single record of Book1 data set.

Please see the bottom-most row that I have bolded in below table. It is the single record that belongs to Book1  data set.

My merging code returns into the final merged table only the five records that belong to Book2 data set. And my code is not stacking the single record belongs to Book1 data set into the final merged table.

Bank_numberCurrent_dateAccount_numberShort_nameCurrency_codeProduct_codeCurrency_short_nameCountryTransitBalanceProductArrears_Band
1028-Feb-101000000000OOOOOOOOO RRRRRRRR01VVVDDDDDDDDRetail1700Personal LoanNPNA
1031-Mar-101000000000OOOOOOOOO RRRRRRRR01VVVDDDDDDDDRetail1700Personal LoanNPNA
1030-Apr-101000000000OOOOOOOOO RRRRRRRR01VVVDDDDDDDDRetail1700Personal LoanNPNA
1031-May-101000000000OOOOOOOOO RRRRRRRR01VVVDDDDDDDDRetail1700Personal LoanNPNA
1030-Jun-101000000000OOOOOOOOO RRRRRRRR01VVVDDDDDDDDRetail1700Personal LoanNPNA
106-Jul-101000000000missing missingmissing missing missing missing 2216Personal Loanwritoff
Solution
‎09-16-2012 02:51 PM
Contributor
Posts: 21

Re: Why cannot I merge these two tables?

data COMBINED_file;

  set file_B

      file_A

       

           ;

by bank_number account_number ;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 192 views
  • 0 likes
  • 3 in conversation