<?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: why these code giving different result? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433200#M107384</link>
    <description>&lt;P&gt;First, read the log. The WARNING you get from the SQL provides the first clue.&lt;/P&gt;
&lt;P&gt;There is a difference between the data and SQL steps in the treatment of variables with the same name: SQL discards any further variables (so you get the values of the first dataset), while the data step reserves one slot and fills it in the sequence in which observations are read, so that (in your case) values from the second dataset appear in the output.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 17:51:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-02-01T17:51:28Z</dc:date>
    <item>
      <title>why these code giving different result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433197#M107383</link>
      <description>&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;
&lt;DIV class="dgrid dgrid-grid ui-widget"&gt;
&lt;DIV class="dgrid-scroller"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;Why these code giving different result?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data B;
	Input ID Name$ Weight;
	cards;
2 A 2
4 B 3
5 Cc 4
7 Dd 5
;
run;

Data A;
	Input ID Name$ Height;
	cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

PROC SQL;
	Create table dummy as
		Select * from A as x inner join B as y
			On x.ID = y.ID;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ID&lt;BR /&gt;&lt;BR /&gt;Name&lt;BR /&gt;&lt;BR /&gt;Height&lt;BR /&gt;&lt;BR /&gt;Weight&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data dummy;
	Merge A (IN = X) B (IN=Y);
	by ID;

	If X and Y;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;1 5 C 2 4&lt;BR /&gt;2 7 D 2 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;ID&lt;BR /&gt;&lt;BR /&gt;Name&lt;BR /&gt;&lt;BR /&gt;Height&lt;BR /&gt;&lt;BR /&gt;Weight&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;1 5 Cc 2 4&lt;BR /&gt;2 7 Dd 2 5&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433197#M107383</guid>
      <dc:creator>thoughtshubham</dc:creator>
      <dc:date>2018-02-01T17:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: why these code giving different result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433200#M107384</link>
      <description>&lt;P&gt;First, read the log. The WARNING you get from the SQL provides the first clue.&lt;/P&gt;
&lt;P&gt;There is a difference between the data and SQL steps in the treatment of variables with the same name: SQL discards any further variables (so you get the values of the first dataset), while the data step reserves one slot and fills it in the sequence in which observations are read, so that (in your case) values from the second dataset appear in the output.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433200#M107384</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-01T17:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: why these code giving different result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433202#M107385</link>
      <description>&lt;P&gt;Your SQL code selects all the variables from A.&amp;nbsp; The only reason for using any data from B is to compare the IDs and select the matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your MERGE on the other hand, takes on data from both data sets.&amp;nbsp; Where there is a match on ID, NAME from B replaces NAME from A as the final value.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-these-code-giving-different-result/m-p/433202#M107385</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-01T17:54:04Z</dc:date>
    </item>
  </channel>
</rss>

