<?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: Flagging sourse with PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/885007#M349673</link>
    <description>&lt;P&gt;The combined dataset now contains only the key variable.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2023 08:37:06 GMT</pubDate>
    <dc:creator>BayzidurRahman</dc:creator>
    <dc:date>2023-07-17T08:37:06Z</dc:date>
    <item>
      <title>Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884981#M349658</link>
      <description>&lt;P&gt;How can we flag the source of each observations&amp;nbsp; after merging two datasets using PROC SQL? The flag variable should identify whether the observation belongs to both datasets or any of them.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 02:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884981#M349658</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-17T02:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884983#M349660</link>
      <description>&lt;P&gt;Use CASE logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select case
            when not missing(A.column) and not missing(B.column) then 'BOTH'
            when not missing(A.column) then 'FROMA'
            when not missing(B.column) then 'FROMB'
            else ' '
         end as Source_Flag length = 5
  from table1 as A
  outer join table2 as B
....;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2023 03:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884983#M349660</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-07-17T03:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884984#M349661</link>
      <description>&lt;P&gt;The easiest way is to use normal SAS code to merge instead since it actually has a concept of source.&amp;nbsp; So code like this will create a FLAG variable with values of 1, 2 or 3 (both).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge a(in=in1) b(in=in2);
  flag = 2*in2 + in1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could do something similar in SQL code with a little work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say you had this SQL code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select ...variable list...
  from A 
  full join B
  on (...criteria...)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could add those IN1 and IN2 flags and the create the new FLAG variable the same way like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as
  select ...variable list...
    ,case when (in1 and in2) then 3 when (in1) then 1 else 2 end as FLAG
  from (select *,1 as in1 from A ) A
  full join (select *,1 as in2 from B) B
  on (...criteria...)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need the CASE instead of the simple arithmetic because the IN1 and IN2 variables will be coded as&amp;nbsp; 1 and missing instead of the 1 and 0 that they would have had when created by the IN= dataset option.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 03:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884984#M349661</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-17T03:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884991#M349666</link>
      <description>&lt;P&gt;Thanks for the code.&lt;/P&gt;&lt;P&gt;When I ran the last set of code with PRC SQL, the flag variable is created ok but the matching variable is missing when flag=2.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 05:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884991#M349666</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-17T05:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884999#M349671</link>
      <description>&lt;P&gt;You need to use the COALESCE function for your key variable(s) in the SELECT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select
  coalesce(a.key,b.key) as key,
  .....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2023 07:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/884999#M349671</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-17T07:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging sourse with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/885007#M349673</link>
      <description>&lt;P&gt;The combined dataset now contains only the key variable.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 08:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-sourse-with-PROC-SQL/m-p/885007#M349673</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-17T08:37:06Z</dc:date>
    </item>
  </channel>
</rss>

