<?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: PROC SQL vs Merge tricky naming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309873#M66773</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;But when I don't rename it, on the by statement, it throws an error "Variable RX_Chain is not on dataset have2". So it seems like I have to rename it..&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2016 21:10:15 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-11-07T21:10:15Z</dc:date>
    <item>
      <title>PROC SQL vs Merge tricky naming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309827#M66763</link>
      <description>&lt;P&gt;Here is some test data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines;
  input RX_Chain $ Exclusion $ CLIENT $ ZIP;
  datalines;
ALD854 N IL 22309
JX139D Y NE 21234
IL603X N MT 99087
AB2009 Y NM 20208
;
run;

data have2;
  infile datalines;
  input Network $ Chain $;
  datalines;
ALD854 00455
JX139D 00139
JX307E 00540
IL603X 00651
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is some PROC SQL that will accomplish what I want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want1 as
  select t1.RX_Chain,
         t1.CLIENT,
		 t1.ZIP,
		 (CASE 
		    WHEN t1.RX_Chain = t2.NETWORK THEN t2.CHAIN
			ELSE t1.RX_Chain
		  END) format=$6. AS RX_Chain
    from have t1 left join have2 t2 on(t1.RX_Chain=t2.Network)
    where t1.Exclusion = 'N';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But, I want to accomplish this with a merge. The trouble is with the naming: RX_Chain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attempted a start at the merge and it looks like this (after sorting initial datasets):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have(in=h) have2(in=h2 rename=(Network=RX_Chain));
  by RX_Chain;
  if h and h2 then RX_Chain=Chain;
  else RX_Chain=RX_Chain;
  if h and Exclusion='N';&lt;BR /&gt;  keep RX_Claim Client ZIP;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I am not getting the same results as the PROC SQL. I know it has to do with the naming of RX_Chain and trying to assign a value to it but basically I'm trying to change the value of RX_Chain in have dataset to Chain in have2 dataset when RX_Chain = Network, or leave it as same value it was if not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 19:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309827#M66763</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-11-07T19:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL vs Merge tricky naming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309854#M66767</link>
      <description>&lt;P&gt;First, why do a merge&amp;nbsp;when you got a working SQL?&lt;/P&gt;
&lt;P&gt;Second, data step handles variable differently than SQL. By renaming Network its values will replace the values provided by Have.&lt;/P&gt;
&lt;P&gt;DOn't rename, use Network in your if logic and assignments.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 20:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309854#M66767</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-11-07T20:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL vs Merge tricky naming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309860#M66769</link>
      <description>&lt;P&gt;Your SQL query contains a duplicate column RX_chain. Beside that, you should get what you want with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge 
	have(in=h1) 
	have2(in=h2 rename=Network=RX_Chain);
by RX_chain; 
if h1 and Exclusion='N';
if h2 then RX_Chain=Chain;
keep RX_Chain Client ZIP;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Nov 2016 20:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309860#M66769</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-07T20:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL vs Merge tricky naming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309873#M66773</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;But when I don't rename it, on the by statement, it throws an error "Variable RX_Chain is not on dataset have2". So it seems like I have to rename it..&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 21:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309873#M66773</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-11-07T21:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL vs Merge tricky naming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309983#M66808</link>
      <description>&lt;P&gt;Apparently I didn't thought it through.&lt;img id="manembarrassed" class="emoticon emoticon-manembarrassed" src="https://communities.sas.com/i/smilies/16x16_man-embarrassed.png" alt="Man Embarassed" title="Man Embarassed" /&gt;&lt;/P&gt;
&lt;P&gt;So we are lucky that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats﻿&lt;/a&gt;&amp;nbsp;came to the rescue&amp;nbsp;&lt;img id="manvery-happy" class="emoticon emoticon-manvery-happy" src="https://communities.sas.com/i/smilies/16x16_man-very-happy.png" alt="Man Very Happy" title="Man Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 09:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-vs-Merge-tricky-naming/m-p/309983#M66808</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-11-08T09:03:43Z</dc:date>
    </item>
  </channel>
</rss>

