<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Merge Question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28959#M6757</link>
    <description>Thank you Scott.  &lt;BR /&gt;
&lt;BR /&gt;
To rephrase my problem:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
merge file1 (in=a) file2 (in=b)&lt;BR /&gt;
if a;&lt;BR /&gt;
&lt;BR /&gt;
this should keep every field from file1 in the resultant file, right?  &lt;BR /&gt;
But it's not.  a field in file1 is missing in the output file.  This is where I m confused..&lt;BR /&gt;
&lt;BR /&gt;
Thankds.</description>
    <pubDate>Fri, 11 Dec 2009 01:34:19 GMT</pubDate>
    <dc:creator>KevinC_</dc:creator>
    <dc:date>2009-12-11T01:34:19Z</dc:date>
    <item>
      <title>Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28957#M6755</link>
      <description>Hello everyone,&lt;BR /&gt;
&lt;BR /&gt;
I am combining a series of files using merges.  One of the fields (first_prin_bal) gets lost halfway thru the merges.  Any input will be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thank you!&lt;BR /&gt;
&lt;BR /&gt;
Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
(first_prin_bal is in the dataset hafc_input2)&lt;BR /&gt;
&lt;BR /&gt;
data wk_rpt1;&lt;BR /&gt;
merge wk_rpt (in=a) hafc_input2 (in=b);&lt;BR /&gt;
by loan_no;&lt;BR /&gt;
if a;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
(* now i select 3 loan_nos and print their first_prin_bal *)&lt;BR /&gt;
&lt;BR /&gt;
select loan_no, first_prin_bal&lt;BR /&gt;
from wk_rpt1&lt;BR /&gt;
where loan_no in ('0010136695', '0012754990', '0015171150');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
                                                             First_Prin_&lt;BR /&gt;
                                    loan_no              Bal&lt;BR /&gt;
                                    ------------------------&lt;BR /&gt;
                                    0010136695      73607.66&lt;BR /&gt;
                                    0012754990      62552.84&lt;BR /&gt;
                                    0015171150      98799.29&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data hafc_mail_wf_nov30;&lt;BR /&gt;
merge hafc_mail_temp(in=a) wk_rpt1 (in=b) cont_hist1(in=c) ;&lt;BR /&gt;
 	by loan_no;&lt;BR /&gt;
 	if b;&lt;BR /&gt;
if in_h_wf = 1 or in_map_wf = 1 then workflow = 'Y';&lt;BR /&gt;
else workflow = 'N';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
( now if i try to print the first_prin_bal for the same 3 loan_nos they aren't there anymore )&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select loan_no, first_prin_bal&lt;BR /&gt;
from hafc_mail_wf_nov30&lt;BR /&gt;
where loan_no in ('0010136695', '0012754990', '0015171150');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                               loan_no            First_Prin_Bal&lt;BR /&gt;
                                ---------------------------------&lt;BR /&gt;
                                0010136695                    .&lt;BR /&gt;
                                0012754990                    .&lt;BR /&gt;
                                0015171150                    .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I think its obvious they got lost in the second merge.  Is it because i have 'if in b'?  How do i keep this field in the output?&lt;BR /&gt;
&lt;BR /&gt;
Thank you!</description>
      <pubDate>Thu, 10 Dec 2009 22:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28957#M6755</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2009-12-10T22:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28958#M6756</link>
      <description>I have to say that your code pieces are working with different input files (something maybe you overlooked?) - you need to verify each file that feeds the MERGE process using PROC PRINT or FREQ (and CONTENTS for that matter) using a WHERE (each individually prior to the MERGE) to confirm that expected input conditions are actually suitable for a merge process.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Dec 2009 01:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28958#M6756</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-11T01:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28959#M6757</link>
      <description>Thank you Scott.  &lt;BR /&gt;
&lt;BR /&gt;
To rephrase my problem:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
merge file1 (in=a) file2 (in=b)&lt;BR /&gt;
if a;&lt;BR /&gt;
&lt;BR /&gt;
this should keep every field from file1 in the resultant file, right?  &lt;BR /&gt;
But it's not.  a field in file1 is missing in the output file.  This is where I m confused..&lt;BR /&gt;
&lt;BR /&gt;
Thankds.</description>
      <pubDate>Fri, 11 Dec 2009 01:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28959#M6757</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2009-12-11T01:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28960#M6758</link>
      <description>Suggest you add the following SAS DATA step diagnostic stmt to identify conditions with your merge process - likely you have a BY variable that is not contributing as you expect:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG '&amp;gt;DIAG-nn&amp;gt;' / _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
where "nn" identifies a unique value when you have more than one of these statements in your SAS program at key points in the processing.  Likely for you there would only be one for the over-simplified DATA step you demonstrated.&lt;BR /&gt;
&lt;BR /&gt;
Also, highly suggest you read up on MERGE with BY statement processing and how SAS deals with contributing observations, variables and values -- both character and numeric.  Also, removing any output format, if declared, may help you detect a difference in an observation with another.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Dec 2009 04:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28960#M6758</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-11T04:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28961#M6759</link>
      <description>The resulting data set will actually contain all fields from all contributing tables.&lt;BR /&gt;
&lt;BR /&gt;
Where you must be very careful is when the same field exists in more than one table (something which might be the cause of what you observe).&lt;BR /&gt;
&lt;BR /&gt;
As proposed: It's worth reading how the merge works exactly because there are some differences to an SQL join. That's a trap you can step in or you can take advantage of the differences depending on the case you have to solve.</description>
      <pubDate>Fri, 11 Dec 2009 09:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28961#M6759</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-12-11T09:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28962#M6760</link>
      <description>KevinC&lt;BR /&gt;
 &lt;BR /&gt;
beware a feature of data set options!&lt;BR /&gt;
Any variable you name as the value of a statement option, like ( in= variable ) on a set or merge, will be dropped - it cannot be "keep"-ed.&lt;BR /&gt;
So, make sure the in= variable does not have the same name as any variable among your inputs, that you want to keep!&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
PeterC</description>
      <pubDate>Fri, 11 Dec 2009 12:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28962#M6760</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-12-11T12:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28963#M6761</link>
      <description>does the dataset cont_hist1 also contain the variable first_prin_bal, and with values missing for these 3 loan_no?</description>
      <pubDate>Fri, 11 Dec 2009 16:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28963#M6761</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2009-12-11T16:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28964#M6762</link>
      <description>Thank you everyone for your valuable iniput!  I really appreciate it.&lt;BR /&gt;
&lt;BR /&gt;
I ran the same program this morning from the top and it worked..  I didn't change the code at all... not sure why or what happened. &lt;BR /&gt;
&lt;BR /&gt;
But I will do what some of you suggested and read up on MERGE.  Thank you again for your help!</description>
      <pubDate>Fri, 11 Dec 2009 21:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Question/m-p/28964#M6762</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2009-12-11T21:12:07Z</dc:date>
    </item>
  </channel>
</rss>

