<?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 MERGE same name columns are not updated in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471781#M120874</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does class_code have any blank values on data2?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please post the log of the merge that is not working, showing the code and any messages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jun 2018 16:25:39 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2018-06-20T16:25:39Z</dc:date>
    <item>
      <title>DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471740#M120865</link>
      <description>&lt;P&gt;I'm merging DATA 1&amp;nbsp;and DATA 2 on the "CODE" variable. I want DATA 2 information update the same name columns in DATA 1. It works fine in demo below. Resulting data WANT has all the columns updated from both datasets merged. However, it doesn't work like this using my actual datasets. Please see screen shot where flag_icd9pc flag takes value 1 indicating MERGE happened but DESC_CODE AND CLASS_CODE columns are not updated from the second data which has information for these two columns. I made sure all same column characteristics in both datasets have same length, format and informat while&amp;nbsp;all being "characters". I formatted them and fixed the variables to the same length before data merge, as below. They all looked fine in&amp;nbsp;Column Attributes in data view by each variables. They're all consistently identical to their lengths, format and informat before merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's going wrong here? My sincere appreciation in advance for your time. Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;informat&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data merge not updated.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21287i7BDD124980CF166C/image-size/large?v=v2&amp;amp;px=999" role="button" title="data merge not updated.png" alt="data merge not updated.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA DATA1; 
INPUT CODE_SYSTEM $	CODE_DESC $ CODE;
CARDS;
.	.	1
.	.	2
.	.	3
.	.	4
.	.	5
.	.	6
HIPPS	DISTANT	7
HIPPS	LOCAL	8
BILLING	DISTANT	9
; 

DATA DATA2; 
INPUT CODE_SYSTEM $	CODE_DESC $ CODE;
CARDS;
ICD10	LOCAL	1
ICD9	REGIONAL	2
CPT	DISTANT	3
ICD10	LOCAL	4
ICD9	DISTANT	5
CPT	REGIONAL 	6
;

DATA WANT; 
INPUT CODE_SYSTEM $	CODE_DESC $ CODE;
CARDS;
ICD10	LOCAL	1
ICD9	REGIONAL	2
CPT	DISTANT	3
ICD10	LOCAL	4
ICD9	DISTANT	5
CPT	REGIONAL 	6
HIPPS	DISTANT	7
HIPPS	LOCAL	8
BILLING	DISTANT	9
;

data WANT1;
merge DATA1 (in=A) 
	  DATA2 (in=B);
by CODE;
if A and B then FLAG_LINKED=1; else FLAG_LINKED=1=0; 
if A;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 15:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471740#M120865</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-20T15:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471774#M120871</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm merging DATA 1&amp;nbsp;and DATA 2 on the "CODE" variable. I want DATA 2 information update the same name columns in DATA 1. It works fine in demo below. Resulting data WANT has all the columns updated from both datasets merged. However, it doesn't work like this using my actual datasets. Please see screen shot where flag_icd9pc flag takes value 1 indicating MERGE happened but DESC_CODE AND CLASS_CODE columns are not updated from the second data which has information for these two columns. I made sure all same column characteristics in both datasets have same length, format and informat while&amp;nbsp;all being "characters". I formatted them and fixed the variables to the same length before data merge, as below. They all looked fine in&amp;nbsp;Column Attributes in data view by each variables. They're all consistently identical to their lengths, format and informat before merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's going wrong here? My sincere appreciation in advance for your time. Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;informat&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;variable &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data merge not updated.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21287i7BDD124980CF166C/image-size/large?v=v2&amp;amp;px=999" role="button" title="data merge not updated.png" alt="data merge not updated.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;With a statement like "However, it doesn't work like this using my actual datasets." the first question is "Are the example values in your data1 and data2 the ones from your actual datasets that do not merge correctly? If not then provide them.&lt;/P&gt;
&lt;P&gt;Note that if you have multiple records with the same value of CODE in both data sets you can get unexpected results. If CODE is duplicated in only one set then different results can happen depending on which set has the multiples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is Code duplicated in DATA1 in your actual data? If so, are all of the Code values supposed to get the same values from data2?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 16:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471774#M120871</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-20T16:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471777#M120872</link>
      <description>&lt;P&gt;You didn't provide an example of when it doesn't work, so we can only guess. One possibility is that you have some values in data1, but want to replace them with data two. If so, you may want to use modify rather than merge. e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA DATA1; 
INPUT CODE_SYSTEM $ CODE_DESC $ CODE;
CARDS;
X   Y   1
X   Y   2
X   Y   3
.   .   4
.   .   5
.   .   6
HIPPS   DISTANT 7
HIPPS   LOCAL   8
BILLING DISTANT 9
; 

DATA DATA2; 
INPUT CODE_SYSTEM $ CODE_DESC $ CODE;
CARDS;
ICD10   LOCAL   1
ICD9    REGIONAL    2
CPT DISTANT 3
ICD10   LOCAL   4
ICD9    DISTANT 5
CPT REGIONAL    6
;

data want;
  set data1;
run;

data want;
  modify want data2 updatemode=nomissingcheck;
  by code;
  if _iorc_=0 then replace;
  else do;
    _error_=0;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 16:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471777#M120872</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-06-20T16:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471780#M120873</link>
      <description>Great. But why did you need this part in the code? &lt;BR /&gt;&lt;BR /&gt;data N.want;&lt;BR /&gt;  set N.data1;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 20 Jun 2018 16:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471780#M120873</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-20T16:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471781#M120874</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does class_code have any blank values on data2?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please post the log of the merge that is not working, showing the code and any messages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 16:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471781#M120874</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-06-20T16:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471799#M120876</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Awesome. Now I can see my parent data is modified with all the information needed. How to flag the rows modified though? All the rows modified are all linked on the linkage variable? My input information is not unique to a data2. Modified dataset had included all rows from both datasets. How to keep data aligned to one of datasets like it's done in data merge?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="awesome.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21293i2A5FF416C7F370B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="awesome.png" alt="awesome.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 17:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471799#M120876</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-20T17:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471807#M120877</link>
      <description>&lt;P&gt;Trying to flag the matched rows from data modify. below didn't create a flag for me. Any idea how to flag matched rows in "modify mode"? thanks in advance.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data n.want;
  modify n.want(in=w) 
		 n.Icd9_pc(in=icd) updatemode=nomissingcheck;
  by omm_proc_cd1;
  if _iorc_=0 then replace;
  else do;
    _error_=0;
    output;
  end;
if w and icd then flag=1; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 17:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471807#M120877</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-20T17:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471810#M120878</link>
      <description>&lt;P&gt;You don't need that step UNLESS you're unsure that the process will do what you want. I included it so that the original file would be left intact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 17:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471810#M120878</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-06-20T17:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471820#M120879</link>
      <description>&lt;P&gt;Read up on the modify statement (e.g.,&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000173361.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000173361.htm&lt;/A&gt; ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your answer will depend upon the combination of what your new file looks like and the updatemode you select.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without seeing your actual datasets it's difficult to say what will do exactly what you want. You could use merge, update or modify. And, for each, you use options to control what will happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 17:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471820#M120879</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-06-20T17:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: DATA MERGE same name columns are not updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471822#M120880</link>
      <description>&lt;P&gt;I don't understand the question. Maybe because you provided a bad example?&lt;/P&gt;
&lt;P&gt;If I just merge the two datasets you provided by CODE then I get exactly what you said you wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge data1 data2 ;
  by code;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that your example case both datasets have only one observation per value of CODE.&lt;/P&gt;
&lt;P&gt;The merge will also work if DATA1 has multiple observations per value of CODE and DATA2 is unique.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if DATA2 has multiple observation per value of CODE then you could get replication of the observations from DATA1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if both have multiple observations per value of CODE then only partial replacement of the values from DATA1 will occur.&amp;nbsp; SAS could run out of records to read from DATA2 for that specific value of CODE. and so not replace the values of the common variables read from DATA1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 17:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-MERGE-same-name-columns-are-not-updated/m-p/471822#M120880</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-20T17:59:59Z</dc:date>
    </item>
  </channel>
</rss>

