<?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 Merge 2 datasets and get 3 outputs in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724615#M9859</link>
    <description>&lt;P&gt;I am trying to merge the 2 datasets by var1 and create 3 datasets outputs, one that has var1 in both, one that has var1 with no income, one that has var1 with no grad_year&lt;/P&gt;&lt;P&gt;the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mydata;&lt;/P&gt;&lt;P&gt;input var1 income;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 400&lt;/P&gt;&lt;P&gt;2 500&lt;/P&gt;&lt;P&gt;3 500&lt;/P&gt;&lt;P&gt;7 600&lt;/P&gt;&lt;P&gt;8 900&lt;/P&gt;&lt;P&gt;9 1000&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mydata2;&lt;/P&gt;&lt;P&gt;var1 grad_year&lt;/P&gt;&lt;P&gt;1 2018&lt;/P&gt;&lt;P&gt;2 2019&lt;/P&gt;&lt;P&gt;4 2020&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 2019&amp;nbsp;&lt;/P&gt;&lt;P&gt;6 2017&lt;/P&gt;&lt;P&gt;11 2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;merging is not an issue for me. I think i should use the 'if then output' statement for this but i could not figure it out.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 08 Mar 2021 19:47:02 GMT</pubDate>
    <dc:creator>jude1</dc:creator>
    <dc:date>2021-03-08T19:47:02Z</dc:date>
    <item>
      <title>Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724615#M9859</link>
      <description>&lt;P&gt;I am trying to merge the 2 datasets by var1 and create 3 datasets outputs, one that has var1 in both, one that has var1 with no income, one that has var1 with no grad_year&lt;/P&gt;&lt;P&gt;the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mydata;&lt;/P&gt;&lt;P&gt;input var1 income;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 400&lt;/P&gt;&lt;P&gt;2 500&lt;/P&gt;&lt;P&gt;3 500&lt;/P&gt;&lt;P&gt;7 600&lt;/P&gt;&lt;P&gt;8 900&lt;/P&gt;&lt;P&gt;9 1000&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mydata2;&lt;/P&gt;&lt;P&gt;var1 grad_year&lt;/P&gt;&lt;P&gt;1 2018&lt;/P&gt;&lt;P&gt;2 2019&lt;/P&gt;&lt;P&gt;4 2020&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 2019&amp;nbsp;&lt;/P&gt;&lt;P&gt;6 2017&lt;/P&gt;&lt;P&gt;11 2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;merging is not an issue for me. I think i should use the 'if then output' statement for this but i could not figure it out.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 19:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724615#M9859</guid>
      <dc:creator>jude1</dc:creator>
      <dc:date>2021-03-08T19:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724622#M9860</link>
      <description>&lt;P&gt;Use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data both no_income no_grad_year;
 merge mydata(in=in1)
           mydata2(in=in2)
     ;
   by var1;
         if in1 and in2 then output both; else    /* line edited */
         if in1 and not in2 then output no_grad_year; 
         else output no_income ;
run;
         &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Mar 2021 05:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724622#M9860</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-09T05:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724624#M9861</link>
      <description>&lt;P&gt;Consider using the IN= parameters on the MERGE statement, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data both  noincome nogradyear;
  merge mydata (in=in1) mydata2 (in=in2);
  by var1;
   ....
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do tests on the values of IN1 and IN2, and then conditional OUTPUT statements based on those tests.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724624#M9861</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-08T20:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724663#M9862</link>
      <description>Thanks for your help. So I wrote the code and countered a new problem. i keep getting error 22-322 and 202-322 on the data2 if statement. data1 and data3 are coming out correct, but not data2. any tips?&lt;BR /&gt;&lt;BR /&gt;data data1 data2 data3;&lt;BR /&gt;merge mydata1(in=a) mydata2(in=b); by var1;&lt;BR /&gt;if a and b; output data1;&lt;BR /&gt;if b and not a then output data2; else output data3;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=data1;&lt;BR /&gt;proc print data=data2;&lt;BR /&gt;proc print data= data3;</description>
      <pubDate>Mon, 08 Mar 2021 21:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724663#M9862</guid>
      <dc:creator>jude1</dc:creator>
      <dc:date>2021-03-08T21:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724668#M9863</link>
      <description>&lt;P&gt;In your code (reformatted to make it easier to read):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1 data2 data3;
    merge mydata1(in=a) 
          mydata2(in=b); by var1;
if a and b; 
output data1;
if b and not a then 
    output data2; 
else 
    output data3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When do you think "if b and not a" will be true?&amp;nbsp; The line "if a and b" has already told SAS that you want only those records where both a and b are true.&amp;nbsp; So you won't get any records where b is false.&amp;nbsp; No code after a false subsetting if will be executed (with the exception of subroutines).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 21:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724668#M9863</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2021-03-08T21:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724670#M9864</link>
      <description>&lt;P&gt;Replace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;if a and b; output data1;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;if a and b then output data1;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 21:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724670#M9864</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-03-08T21:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724756#M9867</link>
      <description>&lt;P&gt;Sorry, I had a typo and missed the word THEN.&lt;/P&gt;
&lt;P&gt;I have edited and corrected my first post.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 05:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/724756#M9867</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-09T05:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/804650#M10399</link>
      <description>I got the same question in exam but I want to clear some concepts, In same question can I use if in1 and in2 then output both; if in1 and not in2 then output no_grad_year;&lt;BR /&gt;If not in1 and in2 then output no_income ;&lt;BR /&gt;And my second question is when we give answer to question in exam if we look at else if in1 and not in2 then output no_grad_year; in output we will get some missing values if I want answer to question and answer is missing value then I’ll write for or type missing value or what ?? Please explain me.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2022 02:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/804650#M10399</guid>
      <dc:creator>Sonia2</dc:creator>
      <dc:date>2022-03-29T02:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge 2 datasets and get 3 outputs</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/804669#M10400</link>
      <description>&lt;P&gt;Your post:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405891"&gt;@Sonia2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I got the same question in exam but I want to clear some concepts, In same question can I use if in1 and in2 then output both; if in1 and not in2 then output no_grad_year;&lt;BR /&gt;If not in1 and in2 then output no_income ;&lt;BR /&gt;And my second question is when we give answer to question in exam if we look at else if in1 and not in2 then output no_grad_year; in output we will get some missing values if I want answer to question and answer is missing value then I’ll write for or type missing value or what ?? Please explain me.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please notice that IN1 and IN2 - each contains 1 for EXIST and 0 for absent.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you didn't arrive to RETURN statement or to the end of the program, the data is still in the memory and you can write it to output, either the same dataset (making duplicates) or to other dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Missing value in a variable is the result of nonexistance record on the dataset that contains this variable.&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>Tue, 29 Mar 2022 05:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merge-2-datasets-and-get-3-outputs/m-p/804669#M10400</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-03-29T05:46:57Z</dc:date>
    </item>
  </channel>
</rss>

