<?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: SAS Match Merge -Create new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290068#M59967</link>
    <description>&lt;P&gt;Hi Reez,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for catching the error, It is not actual code . I have typed the code here as an example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;my actual code with similar logic runs fine but it is failing to create the new variable.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2016 03:16:58 GMT</pubDate>
    <dc:creator>mgorripati</dc:creator>
    <dc:date>2016-08-08T03:16:58Z</dc:date>
    <item>
      <title>SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290064#M59963</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to merge two datasets and create a new variable based on if the data exists in both tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output;
merge source(in=a) client(in=b);
by ID;
if a and b then Level='1';
if b and not a then Level='0';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above works , but does not create the new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i create a new variable during the merge process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can acheive the goal in multiple steps , but is there a way to acheive the above in single step.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 03:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290064#M59963</guid>
      <dc:creator>mgorripati</dc:creator>
      <dc:date>2016-08-08T03:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290065#M59964</link>
      <description>&lt;P&gt;What does your log say?&lt;/P&gt;
&lt;P&gt;It should have some sort of error/warning because your last line is missing a semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if b and not a then Level='0'&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 03:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290065#M59964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-08T03:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290068#M59967</link>
      <description>&lt;P&gt;Hi Reez,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for catching the error, It is not actual code . I have typed the code here as an example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;my actual code with similar logic runs fine but it is failing to create the new variable.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 03:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290068#M59967</guid>
      <dc:creator>mgorripati</dc:creator>
      <dc:date>2016-08-08T03:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290070#M59969</link>
      <description>&lt;P&gt;Well, the logic is correct so your new variable, Level, should be created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Review your log, any drop/keep and output statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without the actual code and log I don't know that we can suggest anything further.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This shows that the logic is fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class1;
	set sashelp.class;
	keep name age height;

	if name in ("Alfred" "Jane" "Mary") then
		delete;
run;

data class2;
	set sashelp.class;
	keep name sex weight;

	if name in ("John" "Joyce" "William") then
		delete;
run;

proc sort data=class1;
	by name;

proc sort data=class2;
	by name;

data want;
	merge class1 (in=a) class2(in=b);
	by name;

	if a and b then
		level=1;
	else if a and not b then
		level=0;
	else
		level=-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 03:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290070#M59969</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-08T03:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290112#M59988</link>
      <description>&lt;P&gt;Should work fine, check out the below. &amp;nbsp;Also note that these binary if statements are far simpler if you use ifc/ifn.&lt;/P&gt;
&lt;PRE&gt;data want;
  merge sashelp.class (in=a) sashelp.class (in=b where=(age &amp;gt; 13));
  by name;
  level=ifc(a and b,"1","0");
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 08:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290112#M59988</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-08T08:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Match Merge -Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290176#M60019</link>
      <description>&lt;P&gt;You have posted working code.&amp;nbsp; You should expect that A and B will be dropped automatically, but LEVEL will be there in the final data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since what you posted is not the actual code you are working with,&amp;nbsp; you may have to post something closer to the actual code to allow someone else to debug it.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 13:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Match-Merge-Create-new-variable/m-p/290176#M60019</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-08T13:04:58Z</dc:date>
    </item>
  </channel>
</rss>

