<?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: Match Merge with all cases output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756505#M238861</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;has found the main problem with the original program.&amp;nbsp; If you want an indicator of which inputs contributed to this observation you need to store that information into a variable, not use the OUTPUT statement.&amp;nbsp; The OUTPUT statement is for writing observations to datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the logic of the flags needs to be cleaned up.&amp;nbsp; Since there are two input datasets there are only three possible combinations of the IN= variables (if both were false then there would be no observation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is simplified logic to capture the three possible combinations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  retain ID Name Age Sex Status;
  length Status $15;
  merge one (in=One) Two (in=two);
  by ID;
  if not two then Status="One only";
  else if not one then Status="Two only";
  else Status= "Both";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Jul 2021 17:22:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-07-26T17:22:19Z</dc:date>
    <item>
      <title>Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756380#M238778</link>
      <description>&lt;PRE&gt;data one;
 input ID $ Name $;
datalines;
A01 Sue
A02 Tom
A05 Key
A10 Jim
;
Run;

data two;
 input ID$ Age  sex $;
datalines;
A01 58 F
A02 20 M
A04 47 F
A10 11 M
;
Run;

Data all;
Merge one(in=in1) Two(in=in2);
By ID;
If in1=1 Then Output One;
if in2=1 then output two;
if (in1=0 and in2=1) then output inboth;
if (in1=0 and in2=1) then output NoMatch1;
if (in1=1 and in2=0) then output NoMatch2;
if (in1=1 OR in2=1) then output allrecs;
if (in1+in2=1) then output nomatch;
Run;
&lt;/PRE&gt;
&lt;P&gt;I have found this code in Support.sas.com and I tried to run it, either the sets is empty or data all is not shown in the output.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 05:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756380#M238778</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-24T05:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756384#M238782</link>
      <description>&lt;P&gt;The last data step is syntactically incorrect and will not compile. Study the log and take corrective action.&lt;/P&gt;
&lt;P&gt;You also have a semantic problem here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (in1=0 and in2=1) then output inboth;
if (in1=0 and in2=1) then output NoMatch1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the conditions are identical.&lt;/P&gt;
&lt;P&gt;Note that the IN= variables are Boolean and can only have values of 0 (false) or 1 (true). The above condition can therefore be written as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not in1 and in2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In Boolean logic, NOT is interpreted first, then AND, and finally OR.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 06:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756384#M238782</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-24T06:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756386#M238784</link>
      <description>&lt;P&gt;Do you look at the log?&lt;/P&gt;
&lt;P&gt;Your second data step throws many errors:&lt;/P&gt;
&lt;PRE&gt;48   Data all;
49   Merge one(in=in1) Two(in=in2);
50   By ID;
51   If in1=1 Then Output One;
                          ---
                          455
52   if in2=1 then output two;
                          ---
                          455
53   if (in1=0 and in2=1) then output inboth;
                                      ------
                                      455
54   if (in1=0 and in2=1) then output NoMatch1;
                                      --------
                                      455
55   if (in1=1 and in2=0) then output NoMatch2;
                                      --------
                                      455
56   if (in1=1 OR in2=1) then output allrecs;
                                     -------
                                     455
57   if (in1+in2=1) then output nomatch;
                                -------
                                455
ERROR 455-185: Data set was not specified on the DATA statement.

58   Run;

&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/STRONG&gt;&lt;/FONT&gt;
WARNING: The data set WORK.ALL may be incomplete.  When this step was stopped there were 0
         observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;To use the name of a data set as the target of an OUTPUT statement the name must be on the DATA statement.&lt;/P&gt;
&lt;P&gt;Since NONE of the data sets used as a target of the OUTPUT appear on the DATA statement the data step does not even execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect to write to multiple data sets the data statement would look like:&lt;/P&gt;
&lt;PRE&gt;Data allrecs one two inboth nomatch1 nomatch2 nomatch ;&lt;/PRE&gt;
&lt;P&gt;Also when any explicit output statement is used the automatic write at the end of the data step is disabled as SAS has&amp;nbsp; been told by you that you "know" when and which data set to write to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We won't go into the bit about the potential problems with writing out to the same data sets on a set/merge statement at this time.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 06:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756386#M238784</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-24T06:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756414#M238807</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Dataset &lt;FONT color="#000080"&gt;&lt;STRONG&gt;all&lt;/STRONG&gt;&lt;/FONT&gt; will not have any data because, you are using &lt;FONT color="#333399"&gt;&lt;STRONG&gt;output&lt;/STRONG&gt; &lt;/FONT&gt;and there is no &lt;FONT color="#000080"&gt;&lt;STRONG&gt;output all in &lt;/STRONG&gt;&lt;FONT color="#000000"&gt;your code.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;FONT color="#000000"&gt;2.As pointed&amp;nbsp;out by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; your data statement should be&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data allrecs one two inboth nomatch1 nomatch2 nomatch ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;FONT color="#000000"&gt;3.The original datasets &lt;FONT color="#000080"&gt;&lt;STRONG&gt;one&lt;/STRONG&gt;&lt;/FONT&gt; and &lt;STRONG&gt;&lt;FONT color="#000080"&gt;two&lt;/FONT&gt; &lt;/STRONG&gt;will be overwritten by the last data step.&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 17:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756414#M238807</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-07-24T17:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756427#M238813</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;If I want to name my dataset as all, then what would be the final? I want output to identify where the record is coming from:&lt;/P&gt;
&lt;PRE&gt;data one;
 input ID $ Name $;
datalines;
A01 Sue
A02 Tom
A05 Key
A10 Jim
;
Run;

data two;
 input ID$ Age  sex $;
datalines;
A01 58 F
A02 20 M
A04 47 F
A10 11 M
;
Run;
Proc sort data=one;
by ID;
Run;

Proc sort data=two;
by ID;
Run;


Data All;
Merge one (in=one) Two (in=two);
By ID;
If in1=1 Then Output One;
if in2=1 then output two;
if (in1=1 and in2=1) then output inboth;
if (in1=1 and in2=0) then output NoMatch1;
if (in1=0 and in2=1) then output NoMatch2;
if (in1=1 OR in2=1) then output allrecs;
if (in1+in2=1) then output nomatch;
Run;&lt;/PRE&gt;
&lt;P&gt;Respectfully,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 21:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756427#M238813</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-24T21:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756430#M238815</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I changed the code to this:&lt;/P&gt;
&lt;PRE&gt;data one;
 input ID $ Name $;
datalines;
A01 Sue
A02 Tom
A05 Key
A10 Jim
;
Run;

data two;
 input ID$ Age  sex $;
datalines;
A01 58 F
A02 20 M
A04 47 F
A10 11 M
;
Run;
Proc sort data=one;
by ID;
Run;

Proc sort data=two;
by ID;
Run;


Data one two inboth Nomatch1 nomatch2 allrecs nomatch;

Merge one (in=One) Two (in=two);
By ID;
If one=1 Then Output One;
if two=1 then output two;
if (one=1 and two=1) then output inboth;
if (one=1 and two=0) then output NoMatch1;
if (two=0 and one=1) then output NoMatch2;
if (one=1 OR two=1) then output allrecs;
if (one + two =1) then output nomatch;
Run;&lt;/PRE&gt;
&lt;P&gt;it runs and gives the result. I want to capture all the cases in one dataset. Each record should be identified to each case belong to. This result can't be used for further step.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 21:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756430#M238815</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-24T21:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756431#M238816</link>
      <description>&lt;P&gt;In order to capture all observations in one row and also capture the case, then please modify the last step as follows.&lt;BR /&gt;The Status variable represents the case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data all;
Retain ID Name Age Sex Status;
Length Status $ 15;
Merge one (in=One) Two (in=two);
By ID;
If one=1 Then  Status="One";
if two=1 then Status="Two";
if (one=1 and two=1) then Status= "Inboth";
if (one=1 and two=0) then Status= "NoMatch1";
if (two=0 and one=1) then Status= "NoMatch2";
if (one=1 OR two=1) then Status= "Allrecs";
if (one + two =1) then Status= "Nomatch";
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 22:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756431#M238816</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-07-24T22:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756457#M238830</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I changed the code to this:&lt;/P&gt;
&lt;PRE&gt;data one;
 input ID $ Name $;
datalines;
A01 Sue
A02 Tom
A05 Key
A10 Jim
;
Run;

data two;
 input ID$ Age  sex $;
datalines;
A01 58 F
A02 20 M
A04 47 F
A10 11 M
;
Run;
Proc sort data=one;
by ID;
Run;

Proc sort data=two;
by ID;
Run;


Data one two inboth Nomatch1 nomatch2 allrecs nomatch;

Merge one (in=One) Two (in=two);
By ID;
If one=1 Then Output One;
if two=1 then output two;
if (one=1 and two=1) then output inboth;
if (one=1 and two=0) then output NoMatch1;
if (two=0 and one=1) then output NoMatch2;
if (one=1 OR two=1) then output allrecs;
if (one + two =1) then output nomatch;
Run;&lt;/PRE&gt;
&lt;P&gt;it runs and gives the result. I want to capture all the cases in one dataset. Each record should be identified to each case belong to. This result can't be used for further step.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your data sets are small you need to show us what you expect for the output. "This result can't be used for further step" doesn't tell us what you expect to do with a further step or what is wrong with the output.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jul 2021 09:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756457#M238830</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-25T09:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756505#M238861</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;has found the main problem with the original program.&amp;nbsp; If you want an indicator of which inputs contributed to this observation you need to store that information into a variable, not use the OUTPUT statement.&amp;nbsp; The OUTPUT statement is for writing observations to datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the logic of the flags needs to be cleaned up.&amp;nbsp; Since there are two input datasets there are only three possible combinations of the IN= variables (if both were false then there would be no observation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is simplified logic to capture the three possible combinations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  retain ID Name Age Sex Status;
  length Status $15;
  merge one (in=One) Two (in=two);
  by ID;
  if not two then Status="One only";
  else if not one then Status="Two only";
  else Status= "Both";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 17:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756505#M238861</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-26T17:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756721#M238976</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want all the cases captured in one data set.&lt;/P&gt;
&lt;P&gt;I thought I can append the different cases.&lt;/P&gt;
&lt;P&gt;What do you think?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 17:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756721#M238976</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-26T17:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756769#M238995</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want all the cases captured in one data set.&lt;/P&gt;
&lt;P&gt;I thought I can append the different cases.&lt;/P&gt;
&lt;P&gt;What do you think?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you MERGE two datasets all cases will be in the output, unless you do something to exclude them.&amp;nbsp; The other possibility is that you want to do what is called an N-to-M join or combination where both N and M are larger than one.&amp;nbsp; That is some of the key values are repeated in both of the source datasets.&amp;nbsp; In that case the MERGE statement will just match them observations by observation and the result will be max(N,M) observations for those values of the BY variables.&amp;nbsp; If instead you used SQL to do an full join then you would match each observation from one dataset with every observation from the other dataset.&amp;nbsp; So you would get N*M observations instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your small example show what you want to produce to clarify what you want.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 19:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756769#M238995</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-26T19:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756854#M239034</link>
      <description>&lt;P&gt;Thanks for the response.&lt;/P&gt;
&lt;PRE&gt;data all;&lt;BR /&gt;set one two inboth Nomatch1 nomatch2 allrecs nomatch;&lt;BR /&gt;Run&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I want to append all the results into one set. If this is doable? I don't need a full join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 03:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/756854#M239034</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-27T03:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759161#M239840</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;A while ago, I posted a question, which I couldn't get what I needed per level of my knowledge.&lt;/P&gt;
&lt;P&gt;I will place a code for other users:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out.mydata;
merge thisdata(in=a) thatdata(in=b);
by hkey;
format find $15.;
if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'
if a then output;
run;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 22:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759161#M239840</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-03T22:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759164#M239842</link>
      <description>&lt;P&gt;So what is your question regarding this program? If you comment out -&amp;nbsp;if a then output - all data from both MERGE datasets will be output.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 23:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759164#M239842</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-08-03T23:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759214#M239870</link>
      <description>&lt;P&gt;Hello saskiwi;&lt;/P&gt;
&lt;P&gt;Are you saying that&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'&lt;/PRE&gt;
&lt;P&gt;would be in the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 06:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759214#M239870</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-04T06:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759231#M239881</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello saskiwi;&lt;/P&gt;
&lt;P&gt;Are you saying that&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'&lt;/PRE&gt;
&lt;P&gt;would be in the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 4.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TRY IT.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 07:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/759231#M239881</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-04T07:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760787#M240611</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I tried it, it give errors:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data unmatched;
merge related1st a (in=a) related2st b (in=b);
by id;
format find $15.;
if a and not b then find="nomatch1";
if not a and b then find = "nomatch2";
run;&lt;BR /&gt;&lt;BR /&gt;p.s. since morning I can't fix it. regards, blueblue&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Aug 2021 23:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760787#M240611</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-10T23:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760789#M240613</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp; - Saying your program gives gives errors but then not posting a SAS log including the errors will not get you answers any quicker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've listed four datasets in your MERGE statement including ones called A and B that perhaps should not be there. How many datasets do you really want to merge?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 23:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760789#M240613</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-08-10T23:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760792#M240616</link>
      <description>&lt;P&gt;Let's look at your program line by line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data unmatched;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you are starting a data step with one output dataset named UNMATCHED.&amp;nbsp; Since it is a one level name it will normally be created in the WORK library.&amp;nbsp; (to learn about when it wouldn't be in WORK you can research the USER libref and USER option).&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;merge related1st a (in=a) related2st b (in=b);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you are telling it to merge 4 datasets named:&amp;nbsp; related1st,&amp;nbsp; a , related2st, and&amp;nbsp; b.&amp;nbsp; For two of them you have told it to create temporary variables named A and B to hold boolean flags that indicate if the dataset contributed to the current by group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect your don't actually have datasets named A and B.&amp;nbsp; Also I would not use A and B as the names for the temporary variables.&amp;nbsp; I like to use names that start with IN for those IN= flag variables.&amp;nbsp; It makes the code referencing them clearer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try using this line instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge related1st (in=in1) related2st (in=in2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is saying that the merge should use the variable ID in both datasets to match the observations.&amp;nbsp; It also means that the observations in both datasets have to be in increasing order of value of ID (that is the data is sorted by ID).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format find $15.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which means you want SAS to use the $ format with a width of 15 when display the value of the FIND variable.&amp;nbsp; Normally there is no need (or reason) to attach a format to a character variable.&amp;nbsp; SAS already knows how to display character variables.&amp;nbsp; I think what you probable want here is to set the LENGTH of the variable FIND.&lt;/P&gt;
&lt;P&gt;So use this statement instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length find $15 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next you have these two IF statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and not b then find="nomatch1";
if not a and b then find = "nomatch2";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you have not included an ELSE so both statements will run, but since it is impossible that both conditions can be true it does not cause any harm.&amp;nbsp; So using the new temporary variable names and including the ELSE that will become:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if in1 and not in2 then find="nomatch1";
else if not in1 and in2 then find = "nomatch2";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And finally you end the step with a RUN: statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if this runs the variable FIND will contain three possible values.&lt;/P&gt;
&lt;PRE&gt;'nomatch1       '
'nomatch2       '
'               '&lt;/PRE&gt;
&lt;P&gt;The ones that are all blank are the observations where both datasets contained observation(s) with that value of ID.&lt;/P&gt;
&lt;P&gt;The ones with nomatch1 are the ID values that only appear in&amp;nbsp;&lt;CODE class=" language-sas"&gt;related1st &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;The ones with nomatch2 are the ID values that only appear in&amp;nbsp;&lt;CODE class=" language-sas"&gt;related2st &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 02:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760792#M240616</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-11T02:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge with all cases output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760972#M240715</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I used a and b to alias my tables.&lt;/P&gt;
&lt;P&gt;I removed a and b and my code ran without errors.&lt;/P&gt;
&lt;P&gt;If we put two ifs then the second if wipes off the result of first if? Do we need to use end statement?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 17:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-with-all-cases-output/m-p/760972#M240715</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-11T17:30:50Z</dc:date>
    </item>
  </channel>
</rss>

