Why I cannot merge these two files?

Reply
Super Contributor
Posts: 338

Why I cannot merge these two files?

Hi SAS Forum,

I have been trying to merge the attahced two files (simplified ver) for hours using the below code but could not.

Specific question:

File_A has a single record whic is not taken into the merged file called "COMBINED_file". There is no any errors in the log too.

Could anyone please help me.

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;

Thanks

Mirisage


Attachment
Attachment
Trusted Advisor
Posts: 2,116

Re: Why I cannot merge these two files?

Worked fine for me.  I got 5 records in the result file.  I am using SAS 9.3 TS0M1 and did the merge with your code and with SQL.

Maybe you need to reframe your question and show us what you want the results to look like.

Doc Muhlbaier

Duke

Trusted Advisor
Posts: 2,116

Re: Why I cannot merge these two files?

I just saw your postings in the SAS Procedures forum.  For the sake of your fellow community members, please post your questions to just one forum.

Thanks,

Doc

Super Contributor
Posts: 338

Re: Why I cannot merge these two files?

Hi Doc,

Thank you.

I am sorry I wanted to post this in SAS procedures forum only. I posted it. Then it did not appear in SAS procedures forum. Then I again posted. Then appeared.

I can now understand what has happened. I have first posted in this forum inadvertently.

I apologize.

Best regards

Mirisage 

New Contributor
Posts: 3

Re: Why I cannot merge these two files?

hi can u please tel me how to merge two files without any common variables.

ex:

first table.

itemcode    item name                      stock

111             colgate toothpaste            10

222            pepsodent                        20

second table.

customer id    name    product   count

501                selva     vatika      3

502                kumar     meera    5

Respected Advisor
Posts: 4,937

Re: Why I cannot merge these two files?

Posted in reply to sachinselva

Next time, you should post your new question as a new discussion...

If you want to merge two datasets on the order of observations (first obs from first dataset with first obs from second dataset, etc.) then do :

data third;

set first;

set second;

run;

dataset third will have as many observations as the shortest of first and second datasets.

PG

PG
PROC Star
Posts: 1,167

Re: Why I cannot merge these two files?

Posted in reply to sachinselva

You could check out the following link, which references a section in the SAS documentation that covers combining SAS datasets. It's powerful, but not like any other language out there (quite different from SQL).

Tom

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p15jvywi5avt3cn1bee8...

Ask a Question
Discussion stats
  • 6 replies
  • 305 views
  • 4 likes
  • 5 in conversation