<?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 data merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534259#M146593</link>
    <description>&lt;P&gt;data merge (drop = w);&lt;/P&gt;&lt;P&gt;merge x (in = a rename = ( new = old))&amp;nbsp;&lt;/P&gt;&lt;P&gt;y (in= b) ;&lt;/P&gt;&lt;P&gt;by t ;&lt;/P&gt;&lt;P&gt;if a and b then d = "e" ;&lt;/P&gt;&lt;P&gt;if a and not b then d = "f" ;&lt;/P&gt;&lt;P&gt;if b and not a then d = "g" ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help converting this into proc sql under case when how to handle in = a and in = b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
    <pubDate>Sun, 10 Feb 2019 07:46:29 GMT</pubDate>
    <dc:creator>kajal_30</dc:creator>
    <dc:date>2019-02-10T07:46:29Z</dc:date>
    <item>
      <title>Data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534230#M146591</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data merge (drop = w);&lt;/P&gt;&lt;P&gt;merge x (in = a rename = ( new = old))&amp;nbsp;&lt;/P&gt;&lt;P&gt;y (in= b) ;&lt;/P&gt;&lt;P&gt;by t ;&lt;/P&gt;&lt;P&gt;if a and b then d = "e" ;&lt;/P&gt;&lt;P&gt;if a and not b then d = "f" ;&lt;/P&gt;&lt;P&gt;if b and not a then d = "g" ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help converting this into proc sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 00:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534230#M146591</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-10T00:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534231#M146592</link>
      <description>&lt;P&gt;Switch the IF/THEN statements to CASE statements. If you're having difficulties, post the code you've tried.&lt;/P&gt;
&lt;P&gt;This assumes a one to one or one to many join, not a many to many join. If it's a many to many join, you cannot replicate it via SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data merge (drop = w);&lt;/P&gt;
&lt;P&gt;merge x (in = a rename = ( new = old))&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y (in= b) ;&lt;/P&gt;
&lt;P&gt;by t ;&lt;/P&gt;
&lt;P&gt;if a and b then d = "e" ;&lt;/P&gt;
&lt;P&gt;if a and not b then d = "f" ;&lt;/P&gt;
&lt;P&gt;if b and not a then d = "g" ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help converting this into proc sql&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 00:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534231#M146592</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-10T00:55:42Z</dc:date>
    </item>
    <item>
      <title>data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534259#M146593</link>
      <description>&lt;P&gt;data merge (drop = w);&lt;/P&gt;&lt;P&gt;merge x (in = a rename = ( new = old))&amp;nbsp;&lt;/P&gt;&lt;P&gt;y (in= b) ;&lt;/P&gt;&lt;P&gt;by t ;&lt;/P&gt;&lt;P&gt;if a and b then d = "e" ;&lt;/P&gt;&lt;P&gt;if a and not b then d = "f" ;&lt;/P&gt;&lt;P&gt;if b and not a then d = "g" ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help converting this into proc sql under case when how to handle in = a and in = b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 07:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534259#M146593</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-10T07:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534265#M146594</link>
      <description>&lt;P&gt;Why do you want to do this in SQL? The data step seems to be a fine tool to me?&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 08:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534265#M146594</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-10T08:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534269#M146595</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data X ;
input T NEW $;
cards;
1 a
2 b
run;
data Y;
input T NEW $;
cards;
1 c
3 d
run;

proc sql;
  create table WANT as 
    select X.NEW as OLD
         , Y.NEW
         , coalesce (X.T, Y.T) as T
         , case when X.T is null then "g"
                when Y.T is null then "f"
                else                  "e" end as D             
    from WORK.X 
           full outer join
         WORK.Y
           on X.T = Y.T;     
quit; 
    &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT face="Liberation Serif"&gt;OLD&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT face="Liberation Serif"&gt;NEW&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT face="Liberation Serif"&gt;T&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT face="Liberation Serif"&gt;D&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;a&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;c&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;e&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;b&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;f&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;d&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT face="Liberation Serif"&gt;g&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 09:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534269#M146595</guid>
      <dc:creator>VRKiwi</dc:creator>
      <dc:date>2019-02-10T09:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534270#M146596</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a SQL Full Join you will only get the same result than with the merge if your variable T is the key in the tables and the relationship between the tables is not many:many.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a CASE statement to work out which table contributes to the result set. If a table doesn't contribute then the value of t from this table will be missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   select 
      ....
      x.new as old,
      case
        when x.t=y.t then 'e'
        when missing(y.t) then 'f'
        when missing*x.t) then 'g'
        else ' '
        end as d,
      ....
    from x full join y
      on x.t=y.t&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 09:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534270#M146596</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-10T09:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534272#M146597</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Using a SQL Full Join you will only get the same result than with the merge if your variable T is the key in the tables and the relationship between the tables is not many:many.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... and also if the key (T here) doesn't have a missing value in any table.&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;</description>
      <pubDate>Sun, 10 Feb 2019 09:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534272#M146597</guid>
      <dc:creator>VRKiwi</dc:creator>
      <dc:date>2019-02-10T09:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Data merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534273#M146598</link>
      <description>&lt;P&gt;I had to merge your identical questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PLEASE DO NOT DOUBLE-POST.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 09:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-merge/m-p/534273#M146598</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-10T09:34:01Z</dc:date>
    </item>
  </channel>
</rss>

