<?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: merging in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504723#M1004</link>
    <description>&lt;P&gt;Believe it or not, that's a standard result from MERGE.&amp;nbsp; The problem is this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS reads each observation only once as it merges the data.&amp;nbsp; That means it reads each observation from SEC_DATA only once.&amp;nbsp; It retains the values it has, which is why NAME repeats in the merged data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you change "ANNA" to "MOLLY" SAS retains the value "MOLLY".&amp;nbsp; It never goes back and re-reads "ANNA" from the incoming data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to fix this.&amp;nbsp; The easiest way is to create a new variable (NAME2) based on NAME plus your other conditions.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Oct 2018 14:02:55 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-10-16T14:02:55Z</dc:date>
    <item>
      <title>merging</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504710#M999</link>
      <description>&lt;P&gt;HI!&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i'm trying to merge 2 datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i merges this tables i want to change column "name" with condition "st = "POMPLE" and DATE &amp;lt; "01MAR2017"d" , but program changes all observation. Why it's happen? I know that if i do it in a new data step, everything will be executed correctly. I want to undenstand how SAS creating PDV in merging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data first_data;&lt;BR /&gt;input st $ date date9. ;&lt;BR /&gt;attrib date format=date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;POMPLE 28FEB2017&lt;BR /&gt;POMPLE 28FEB2017&lt;BR /&gt;POMPLE 01MAR2017&lt;BR /&gt;POMPLE 01MAR2017&lt;BR /&gt;POMPLE 02MAR2017&lt;BR /&gt;POMPLE 02MAR2017&lt;BR /&gt;MINR 28FEB2017&lt;BR /&gt;MINR 02MAR2017&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data sec_data;&lt;BR /&gt;input st $ name $;&lt;BR /&gt;datalines;&lt;BR /&gt;POMPLE ANNA&lt;BR /&gt;MINR GERRY&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=first_data;&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=sec_data;&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;data merges_clon;&lt;BR /&gt;merge first_data(in=a) sec_data(in=b);&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;data merges;&lt;BR /&gt;merge first_data(in=a) sec_data(in=b);&lt;BR /&gt;by st;&lt;BR /&gt;IF st = "POMPLE" and DATE &amp;lt; "01MAR2017"d THEN&lt;BR /&gt;name = "MOLLY";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 13:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504710#M999</guid>
      <dc:creator>Terekhin</dc:creator>
      <dc:date>2018-10-16T13:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: merging</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504722#M1003</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175977"&gt;@Terekhin&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this what you are trying to do?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first_data;
input st $ date date9. ;
attrib date format=date9.;
datalines;
POMPLE 28FEB2017
POMPLE 28FEB2017
POMPLE 01MAR2017
POMPLE 01MAR2017
POMPLE 02MAR2017
POMPLE 02MAR2017
MINR 28FEB2017
MINR 02MAR2017
;
run;

data sec_data;
input st $ name $;
datalines;
POMPLE ANNA
MINR GERRY
;
run;

proc sort data=first_data;
by st;
run;
proc sort data=sec_data;
by st;
run;
data merges_clon;
merge first_data(in=a where=(st="POMPLE" and date&amp;lt;"01MAR2017"d)) sec_data(in=b);
by st;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 13:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504722#M1003</guid>
      <dc:creator>V_27</dc:creator>
      <dc:date>2018-10-16T13:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: merging</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504723#M1004</link>
      <description>&lt;P&gt;Believe it or not, that's a standard result from MERGE.&amp;nbsp; The problem is this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS reads each observation only once as it merges the data.&amp;nbsp; That means it reads each observation from SEC_DATA only once.&amp;nbsp; It retains the values it has, which is why NAME repeats in the merged data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you change "ANNA" to "MOLLY" SAS retains the value "MOLLY".&amp;nbsp; It never goes back and re-reads "ANNA" from the incoming data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to fix this.&amp;nbsp; The easiest way is to create a new variable (NAME2) based on NAME plus your other conditions.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 14:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504723#M1004</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-16T14:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: merging</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504725#M1005</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175977"&gt;@Terekhin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;HI!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS 9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i'm trying to merge 2 datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i merges this tables i want to change column "name" with condition "st = "POMPLE" and DATE &amp;lt; "01MAR2017"d" , but program changes all observation. Why it's happen? I know that if i do it in a new data step, everything will be executed correctly. I want to undenstand how SAS creating PDV in merging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data first_data;&lt;BR /&gt;input st $ date date9. ;&lt;BR /&gt;attrib date format=date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;POMPLE 28FEB2017&lt;BR /&gt;POMPLE 28FEB2017&lt;BR /&gt;POMPLE 01MAR2017&lt;BR /&gt;POMPLE 01MAR2017&lt;BR /&gt;POMPLE 02MAR2017&lt;BR /&gt;POMPLE 02MAR2017&lt;BR /&gt;MINR 28FEB2017&lt;BR /&gt;MINR 02MAR2017&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data sec_data;&lt;BR /&gt;input st $ name $;&lt;BR /&gt;datalines;&lt;BR /&gt;POMPLE ANNA&lt;BR /&gt;MINR GERRY&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=first_data;&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=sec_data;&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;data merges_clon;&lt;BR /&gt;merge first_data(in=a) sec_data(in=b);&lt;BR /&gt;by st;&lt;BR /&gt;run;&lt;BR /&gt;data merges;&lt;BR /&gt;merge first_data(in=a) sec_data(in=b);&lt;BR /&gt;by st;&lt;BR /&gt;IF st = "POMPLE" and DATE &amp;lt; "01MAR2017"d THEN&lt;BR /&gt;name = "MOLLY";&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is part of the mechanics of the data step.&lt;/P&gt;
&lt;P&gt;Variables from input datasets are always retained (not set to missing), so what happens is this:&lt;/P&gt;
&lt;P&gt;In the first iteration of the data step, both datasets are read, the condition is found to be true, and name is set to MOLLY. From the second iteration on, no further observations for st = 'POMPLE' are present in the second dataset, so the value 'MOLLY' is retained and ends up in all output rows.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 14:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging/m-p/504725#M1005</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-16T14:06:31Z</dc:date>
    </item>
  </channel>
</rss>

