<?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: DATA step: merge in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14455#M2310</link>
    <description>Thanks for sharing the great knowledge.&lt;BR /&gt;
&lt;BR /&gt;
I am reading, practicing and learning. Super software.</description>
    <pubDate>Wed, 15 Jun 2011 21:27:40 GMT</pubDate>
    <dc:creator>bncoxuk</dc:creator>
    <dc:date>2011-06-15T21:27:40Z</dc:date>
    <item>
      <title>DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14447#M2302</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a question regarding the merge statement in the DATA step, as in the example below.&lt;BR /&gt;
&lt;BR /&gt;
The data1 has variables of policy, location and age_1, and the data2 has variables of policy, location and age_2. The data3 is created by merging these two data sets. The new variable age is set to the value 'X' if both age_1 and age_2 have missing values in the merged data3. Surprisingly, after the DATA step, the values for both age_1 and age_2 became missing. Where is the problem? Please advise.&lt;BR /&gt;
&lt;BR /&gt;
DATA work.data3;&lt;BR /&gt;
	MERGE work.data1 work.data2;&lt;BR /&gt;
	BY policy location;&lt;BR /&gt;
	IF MISSING(age_1) AND MISSING(age_2) THEN age='X'; &lt;BR /&gt;
RUN;</description>
      <pubDate>Wed, 15 Jun 2011 18:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14447#M2302</guid>
      <dc:creator>Kevin_Graduate</dc:creator>
      <dc:date>2011-06-15T18:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14448#M2303</link>
      <description>You need to generate some self-initiated diagnostics in your SAS log to see why your SAS DATA step behaved as you explain.  Add this statement and I believe that you will have the answer to your question:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 15 Jun 2011 18:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14448#M2303</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-15T18:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14449#M2304</link>
      <description>i just like to know if I can compare variables in two different datasets during merge. If this is wrong, then I should use another data step after the merge?&lt;BR /&gt;
&lt;BR /&gt;
anyone can suggest?</description>
      <pubDate>Wed, 15 Jun 2011 19:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14449#M2304</guid>
      <dc:creator>Kevin_Graduate</dc:creator>
      <dc:date>2011-06-15T19:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14450#M2305</link>
      <description>I think you need to use the IN option on the datasets.  If age is a number, then the age='X' won't work.&lt;BR /&gt;
&lt;BR /&gt;
DATA work.data3;&lt;BR /&gt;
MERGE work.data1(in=d1) work.data2(in=d2);&lt;BR /&gt;
BY policy location;&lt;BR /&gt;
IF not d1 and not d2 THEN age='X'; &lt;BR /&gt;
RUN;</description>
      <pubDate>Wed, 15 Jun 2011 19:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14450#M2305</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-06-15T19:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14451#M2306</link>
      <description>Thanks for your reply, DBailey. But my question is actually:&lt;BR /&gt;
&lt;BR /&gt;
Is it right to compare two variables a, b, if they are in two different datasets of data1, and data2? So,&lt;BR /&gt;
&lt;BR /&gt;
DATA test;&lt;BR /&gt;
MERGE data1 data2; &lt;BR /&gt;
BY ID_1;&lt;BR /&gt;
IF a+b &amp;gt; 10;  /*Note: a in data1, b in data2*/&lt;BR /&gt;
&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
My question is: does the merge happens before the IF a+b&amp;gt;10 statement? If this is true, then the code does not cause problem. But if the merge happens after that, then this causes problem, as variable a does not exist at all the data2.</description>
      <pubDate>Wed, 15 Jun 2011 19:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14451#M2306</guid>
      <dc:creator>Kevin_Graduate</dc:creator>
      <dc:date>2011-06-15T19:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14452#M2307</link>
      <description>If I remember by program data vector correctly, the PDV is filled in as the input data sets are read.  The code you have included should not cause a problem.  You might have an issue with missing values which might propogate to your answer.</description>
      <pubDate>Wed, 15 Jun 2011 20:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14452#M2307</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-06-15T20:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14453#M2308</link>
      <description>Hello Kevin,&lt;BR /&gt;
&lt;BR /&gt;
This code:&lt;BR /&gt;
DATA test;&lt;BR /&gt;
  MERGE data1 data2;  &lt;BR /&gt;
  BY ID_1;&lt;BR /&gt;
  IF a+b &amp;gt; 10; /*Note: a in data1, b in data2*/&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
works correctly. Merge happens before IF will execute. However, your logic in the initial code has a problem:&lt;BR /&gt;
  IF MISSING(age_1) AND MISSING(AGE_2) THEN age='X';&lt;BR /&gt;
&lt;BR /&gt;
You do not specify what to do if age_1 is missing and age_2 is not. This creates missing values for age. The same is true when age_1 is not missing but age_2 is missing.&lt;BR /&gt;
&lt;BR /&gt;
This is a test program:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data data1;&lt;BR /&gt;
  ID_1=1; a=5; output;&lt;BR /&gt;
  ID_1=1; a=.; output;&lt;BR /&gt;
  ID_1=2; a=3; output;&lt;BR /&gt;
  ID_1=2; a=0; output;&lt;BR /&gt;
run;&lt;BR /&gt;
data data2;&lt;BR /&gt;
  ID_1=1; b=6; output;&lt;BR /&gt;
  ID_1=1; b=.; output;&lt;BR /&gt;
  ID_1=2; b=8; output;&lt;BR /&gt;
  ID_1=2; b=1; output;&lt;BR /&gt;
run;&lt;BR /&gt;
DATA test;&lt;BR /&gt;
  MERGE data1 data2; &lt;BR /&gt;
  IF MISSING(a) AND MISSING(b) THEN age='X';&lt;BR /&gt;
  BY ID_1;&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Dataset test:&lt;BR /&gt;
[pre]&lt;BR /&gt;
ID_1    a       b      age&lt;BR /&gt;
1	5	6	&lt;BR /&gt;
1	.	.	X&lt;BR /&gt;
2	3	8	&lt;BR /&gt;
2	0	1	&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 15 Jun 2011 20:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14453#M2308</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-06-15T20:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14454#M2309</link>
      <description>As I mentioned, the PUTLOG command would have given you the answer to your latest curios question about SAS MERGE processing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 15 Jun 2011 20:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14454#M2309</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-15T20:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14455#M2310</link>
      <description>Thanks for sharing the great knowledge.&lt;BR /&gt;
&lt;BR /&gt;
I am reading, practicing and learning. Super software.</description>
      <pubDate>Wed, 15 Jun 2011 21:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14455#M2310</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-06-15T21:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: DATA step: merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14456#M2311</link>
      <description>Thanks for the answer, Dbailey.</description>
      <pubDate>Wed, 15 Jun 2011 21:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DATA-step-merge/m-p/14456#M2311</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-06-15T21:28:18Z</dc:date>
    </item>
  </channel>
</rss>

