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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 756 views
  • 0 likes
  • 3 in conversation