<?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: Combing tables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809669#M33775</link>
    <description>Actually what's my requirement is there are two tables both x and y. In x it has 3 columns named a,b,c both are numeric I'm extremely sorry it's my bad and y table has 4 columns a,b,c and amount. Both in x,y tables a,b,c column values are same . When joining these tables based on a,b,c columns if a value doesn't exist in x or in y then for that particular value the amount should be considered as 0.</description>
    <pubDate>Mon, 25 Apr 2022 12:31:14 GMT</pubDate>
    <dc:creator>Pandu2</dc:creator>
    <dc:date>2022-04-25T12:31:14Z</dc:date>
    <item>
      <title>Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809625#M33767</link>
      <description>Hi All,&lt;BR /&gt;I hope everyone is doing good. I require some assistance from you all regrading joining two tables based on some condition.&lt;BR /&gt;&lt;BR /&gt;I've two tables x and y in x it has 3 columns which are present in table y as well and an extra column is there for y table named amount . These two tables should be joined based on those 3 fields named a,b,c and it should have a condition like&lt;BR /&gt;&lt;BR /&gt;If the values of the 3 fields in x doesn't exist in the columns of y table then  for those values the amount should be equal to 0 instead of excluding them  those &lt;BR /&gt;who doesn't exist &lt;BR /&gt;Example table:&lt;BR /&gt;X - table :. Y - table:&lt;BR /&gt;a b c         a. b. c. amount&lt;BR /&gt;1 5 15.      1. 5. 15. 4&lt;BR /&gt;2 6 26.      2. 6. 26. 9&lt;BR /&gt;3 7 37.      3. 7. 37. 8&lt;BR /&gt;4 8 48&lt;BR /&gt;&lt;BR /&gt;Joined table (required table):&lt;BR /&gt;a. b. c. amount&lt;BR /&gt;1. 5. 15. 4&lt;BR /&gt;2. 6. 26. 9&lt;BR /&gt;3. 7. 37. 8&lt;BR /&gt;4. 8. 48. 0&lt;BR /&gt;&lt;BR /&gt;Ps: I apologise there are no dots in the data, please don't consider them.&lt;BR /&gt;&lt;BR /&gt;Thankyou.</description>
      <pubDate>Mon, 25 Apr 2022 07:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809625#M33767</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T07:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809643#M33768</link>
      <description>&lt;P&gt;Please provide the data as SAS data step code. You can type in the SAS data step code yourself, or via these instructions: &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 10:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809643#M33768</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-25T10:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809645#M33769</link>
      <description>Data x;&lt;BR /&gt;Input a b c $4;&lt;BR /&gt;Datalines;&lt;BR /&gt;1  5  15&lt;BR /&gt;2   6   26&lt;BR /&gt;3   7    37&lt;BR /&gt;4.  8    48&lt;BR /&gt;;&lt;BR /&gt;Data y;&lt;BR /&gt;Input a b c $4, amount 10.;&lt;BR /&gt;Datalines;&lt;BR /&gt;1. 5   15   4&lt;BR /&gt;2.  6.  26   5&lt;BR /&gt;3.  7.   36.  9&lt;BR /&gt;4.   8.   48&lt;BR /&gt;;&lt;BR /&gt;Data joined;&lt;BR /&gt;Input a b c $4, amount 10.;&lt;BR /&gt;Datalines;&lt;BR /&gt;1.  5  15.  4&lt;BR /&gt;2.   6.  26.  5&lt;BR /&gt;3.   7.  37.   9&lt;BR /&gt;4.   8.  48.  0&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Apr 2022 10:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809645#M33769</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T10:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809648#M33770</link>
      <description>&lt;P&gt;Please test code before posting.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 10:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809648#M33770</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-25T10:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809654#M33771</link>
      <description>That's my datasets x and y and I require joined dataset</description>
      <pubDate>Mon, 25 Apr 2022 11:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809654#M33771</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T11:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809655#M33772</link>
      <description>&lt;P&gt;Log excerpt:&lt;/P&gt;
&lt;PRE&gt; 76         ;
 77         Data y;
 78         Input a b c $4, amount 10.;
                          _
                          22
                          200
 ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: ein Name, eine numerische Konstante, arrayname, #, (, +, -, /, //, 
               ;, @, @@.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 79         Datalines;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.Y may be incomplete.  When this step was stopped there were 0 observations and 4 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              632.06k
       OS Memory           23976.00k
       Timestamp           25.04.2022 11:29:39 vorm.
       Step Count                        25  Switch Count  2
       Page Faults                       0
       Page Reclaims                     114
       Page Swaps                        0
       Voluntary Context Switches        11
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 84         ;
 
 
 85         Data joined;
 86         Input a b c $4, amount 10.;
                          _
                          22
                          200
 ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: ein Name, eine numerische Konstante, arrayname, #, (, +, -, /, //, 
               ;, @, @@.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 87         Datalines;
 
 NOTE: The SAS System stopped processing this step because of errors.
&lt;/PRE&gt;
&lt;P&gt;As a &lt;STRONG&gt;very important&lt;/STRONG&gt; basic exercise, fix these issues before proceeding.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 11:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809655#M33772</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-25T11:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809660#M33774</link>
      <description>&lt;P&gt;Just to a merge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  merge x y;
  by a b c ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the values need to actually match.&amp;nbsp; So the third observations where X has C='37' and Y has C='36.' will not match.&amp;nbsp; So your output will have 5 observations instead of 4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you really intend that C be defined as a character variable but keep A and B as numeric?&lt;/P&gt;
&lt;P&gt;Do&amp;nbsp; you really want to replace missing values of amount with zero?&amp;nbsp; If so add some code to the data step. For example like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;amount = sum(amount,0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 12:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809660#M33774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T12:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809669#M33775</link>
      <description>Actually what's my requirement is there are two tables both x and y. In x it has 3 columns named a,b,c both are numeric I'm extremely sorry it's my bad and y table has 4 columns a,b,c and amount. Both in x,y tables a,b,c column values are same . When joining these tables based on a,b,c columns if a value doesn't exist in x or in y then for that particular value the amount should be considered as 0.</description>
      <pubDate>Mon, 25 Apr 2022 12:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809669#M33775</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T12:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809671#M33776</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Actually what's my requirement is there are two tables both x and y. In x it has 3 columns named a,b,c both are numeric I'm extremely sorry it's my bad and y table has 4 columns a,b,c and amount. Both in x,y tables a,b,c column values are same . When joining these tables based on a,b,c columns if a doesn't exist in x or in y then for that particular value the amount should be considered as 0.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  merge x y;
  by a b c ;
  amount=sum(amount,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 12:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809671#M33776</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T12:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809674#M33777</link>
      <description>Thanks alot. Is that possible by using proc SQL?.</description>
      <pubDate>Mon, 25 Apr 2022 12:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809674#M33777</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T12:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809680#M33778</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks alot. Is that possible by using proc SQL?.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. Try it.&lt;/P&gt;
&lt;LI-SPOILER&gt;Use a FULL JOIN and the COALESCE function for all variables, e.g.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coalesce(x.a,y.a) as a&lt;/CODE&gt;&lt;/PRE&gt;
Coalesce y.amount with 0.&lt;/LI-SPOILER&gt;</description>
      <pubDate>Mon, 25 Apr 2022 12:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809680#M33778</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-25T12:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809681#M33779</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks alot. Is that possible by using proc SQL?.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; It is just a lot harder to type and understand than basic SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select coalesce(x.a,y.a) as a
     , coalesce(x.b,y.b) as b
     , coalesce(x.c,y.c) as c
     , coalesce(y.amount,0) as amount
from x full join y
on x.a=y.a and x.b=y.b and x.c=y.c
order by 1,2,3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus if there are replications of the combinations of the A,B,C key variables then MERGE and FULL JOIN might return different results since how the handle many to many joins is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to include the observations that appear in X then it is a little easer to code use a LEFT JOIN.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select x.*
     , coalesce(y.amount,0) as amount
from x left join y
on x.a=y.a and x.b=y.b and x.c=y.c
order by x.a,x.b,x.c
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 13:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809681#M33779</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T13:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809683#M33780</link>
      <description>This didn't work it gave me all blank values in amount column.</description>
      <pubDate>Mon, 25 Apr 2022 13:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809683#M33780</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T13:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809685#M33781</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;This didn't work it gave me all blank values in amount column.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can't be with the data you posted (once I fixed a couple of ERRORs):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input (a b c) (:$4.);
datalines;
1 5 15
2 6 26
3 7 37
4 8 48
;

data y;
infile datalines truncover;
input (a b c) (:$4.) amount :10.;
datalines;
1 5 15 4
2 6 26 5
3 7 36 9
4 8 48
;

proc sql;
create table want as
  select
    coalesce(x.a,y.a) as a,
    coalesce(x.b,y.b) as b,
    coalesce(x.c,y.c) as c,
    coalesce(y.amount,0) as amount
  from x full join y
  on x.a = y.a and x.b = y.b and x.c = y.c
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;a	b	c	amount
1	5	15	4
2	6	26	5
3	7	36	9
3	7	37	0
4	8	48	0
&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 13:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809685#M33781</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-25T13:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809689#M33783</link>
      <description>Infact the amount column should have 0 value only if the values of x table doesn't exist in y table. Otherwise the amount column values shouldn't be changed. Thanks.</description>
      <pubDate>Mon, 25 Apr 2022 13:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809689#M33783</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T13:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809690#M33784</link>
      <description>&lt;P&gt;You will not get missing AMOUNT if you use either SUM(AMOUNT,0) or COALESE(AMOUNT,0).&amp;nbsp; Cannot happen.&lt;/P&gt;
&lt;P&gt;If you used select * in PROC SQL then the first variable named AMOUNT that it sees will be the one saved into the dataset.&amp;nbsp; So if you used&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select x.*,coalesce(y.amount,0) as amount&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And there was already a variable named AMOUNT in the X dataset then that is the one you see and the result of the COALESCE() function call will not make it into the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the code you used.&lt;/P&gt;
&lt;P&gt;Make a simplified example that demonstrates the issue.&amp;nbsp; Share it with us using simple data steps to create the two datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 13:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809690#M33784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T13:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809701#M33786</link>
      <description>Thankyou it worked out really well.</description>
      <pubDate>Mon, 25 Apr 2022 14:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809701#M33786</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T14:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809702#M33787</link>
      <description>Thankyou. it is working</description>
      <pubDate>Mon, 25 Apr 2022 14:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809702#M33787</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-04-25T14:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809706#M33788</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Infact the amount column should have 0 value only if the values of x table doesn't exist in y table. Otherwise the amount column values shouldn't be changed. Thanks.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So another reason to not wasting your time trying to shoehorn this into SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge x y(in=iny);
  by a b c ;
  if not iny then amount=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 14:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809706#M33788</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-25T14:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combing tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809713#M33789</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have the two following requirements.&lt;/P&gt;
&lt;PRE&gt;These two tables should be joined based on those 3 fields named a,b,c and it should have a condition like
If the values of the 3 fields in x doesn't exist in the columns of y table then for those values the amount should be equal to 0 instead of excluding them those
who doesn't exist.&lt;/PRE&gt;
&lt;P&gt;While there could be many approaches to solve this problem,&lt;BR /&gt;one solution for this is to use a full outer join.&lt;BR /&gt;Proc SQL or data step merge cam be used.&lt;BR /&gt;As you are using three columns to base your join upon, &lt;BR /&gt;one approach is to create a composite key. I have used a simple approach of concatenating the three column values.&lt;BR /&gt;More sophisticated approaches can be used.&lt;BR /&gt;Your second table i.e., y has missing values for amount, it is better to have them as zero.&lt;BR /&gt;(you may need them in arithmetic operations. Using missing values in an expression generates missing values. This can be avoided by having them as zeros rather than keep them missing).&lt;BR /&gt;I suggest the following code. Modify to suit your needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input (a b c) (:$4.);
datalines;
1 5 15
2 6 26
3 7 37
4 8 48
;

data y;
infile datalines truncover;
input (a b c) (:$4.) amount :10.;
datalines;
1 5 15 4
2 6 26 5
3 7 36 9
4 8 48
;
data left;
retain key a b c;
set x;
key=catx('-',a,b,c);
run;

data right;
retain key a b c;
set y;
key=catx('-',a,b,c);
run;
proc sort data=left;
by key;
run;
proc sort data=right;
by key;
run;
data want (drop=key);
merge left right;
by key;
amount=coalesce(amount,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1650898350787.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70840i1D76822B68325B31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1650898350787.png" alt="Sajid01_0-1650898350787.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 14:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Combing-tables/m-p/809713#M33789</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-04-25T14:52:42Z</dc:date>
    </item>
  </channel>
</rss>

