BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
AUTigers
Calcite | Level 5

data COMBINED_file;

  set file_B

      file_A

       

           ;

by bank_number account_number ;

run;

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

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

Mirisage
Obsidian | Level 7

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
AUTigers
Calcite | Level 5

data COMBINED_file;

  set file_B

      file_A

       

           ;

by bank_number account_number ;

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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