<?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: Merging in SQL, want to write this code in sql: if (ab and mn) = 1 then flag = &amp;quot;Y&amp;quot;; el in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804520#M316833</link>
    <description>&lt;P&gt;First comment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if (a and b) = 1 then&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is basically identical to (in this case with exactly two data sets you can't ever have the case of a=0 and b=0 )&lt;/P&gt;
&lt;PRE&gt;if a and b then &lt;/PRE&gt;
&lt;P&gt;You will have to show the rest of your proposed SQL as what you request seriously depends on the remainder of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last, you may want to consider use of 1/0 numeric coded variables instead of character 'Y' and 'N'.&lt;/P&gt;
&lt;P&gt;For one thing your flag code could be reduced to:&lt;/P&gt;
&lt;PRE&gt;Flag = (a and b);&lt;/PRE&gt;
&lt;P&gt;no "else" needed.&lt;/P&gt;
&lt;P&gt;There are lots of ways to get counts and information about 1/0 coded values in summary that require much more work with 'Y' and 'N'. Such as Sum of Flag is the number of FLAG=1, mean is the percent of Flag=1 as a decimal (.5 = 50% displayed with a percent format).&lt;/P&gt;
&lt;P&gt;Also you can assign a custom format to show 'Y' or 'Yes' or 'Flagged for xxxx' to make the value more readable of if desired. (You can still do the format with character values, just mean there is no reason to use character if you want to be human readable)&lt;/P&gt;</description>
    <pubDate>Mon, 28 Mar 2022 14:36:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-03-28T14:36:27Z</dc:date>
    <item>
      <title>Merging in SQL, want to write this code in sql: if (a and b) = 1 then flag = "Y"; else flag = "N";</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804497#M316818</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data ab;
input id name$;
cards;
1 A
2 B
3 C
4 D
9 Z
;
RUN;

data mn;
input id name$;
cards;
1 A
2 B
3 C
4 D
4 N
5 E
6 F 
;
RUN;
&lt;BR /&gt;/* please help me to write below code in sql, its little important*/
DATA TEST;
MEREG ab(in=a) mn(in=b);
by id;
if (a and b) = 1 then flag = "Y"; 
else flag = "N";
run;
proc print data = test;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Mar 2022 15:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804497#M316818</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2022-03-28T15:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging in SQL, want to write this code in sql: if (ab and mn) = 1 then flag = "Y"; el</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804520#M316833</link>
      <description>&lt;P&gt;First comment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if (a and b) = 1 then&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is basically identical to (in this case with exactly two data sets you can't ever have the case of a=0 and b=0 )&lt;/P&gt;
&lt;PRE&gt;if a and b then &lt;/PRE&gt;
&lt;P&gt;You will have to show the rest of your proposed SQL as what you request seriously depends on the remainder of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last, you may want to consider use of 1/0 numeric coded variables instead of character 'Y' and 'N'.&lt;/P&gt;
&lt;P&gt;For one thing your flag code could be reduced to:&lt;/P&gt;
&lt;PRE&gt;Flag = (a and b);&lt;/PRE&gt;
&lt;P&gt;no "else" needed.&lt;/P&gt;
&lt;P&gt;There are lots of ways to get counts and information about 1/0 coded values in summary that require much more work with 'Y' and 'N'. Such as Sum of Flag is the number of FLAG=1, mean is the percent of Flag=1 as a decimal (.5 = 50% displayed with a percent format).&lt;/P&gt;
&lt;P&gt;Also you can assign a custom format to show 'Y' or 'Yes' or 'Flagged for xxxx' to make the value more readable of if desired. (You can still do the format with character values, just mean there is no reason to use character if you want to be human readable)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 14:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804520#M316833</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-28T14:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merging in SQL, want to write this code in sql: if (ab and mn) = 1 then flag = "Y"; el</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804526#M316838</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17460"&gt;@ManoharNath&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code supplied below does exactly the same as your data step, it&amp;nbsp;detects matches on ID only, so 4 D and 4 N are both flagged as "Y", even if 4 N is only found in one table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's all right then use the code as is, otherwise use the ON-clause in comments instead. And may I know why you want to do this in Proc SQL, when you have a working solution in a Data Step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data ab;
input id name$;
cards;
1 A
2 B
3 C
4 D
9 Z
;
RUN;

data mn;
input id name$;
cards;
1 A
2 B
3 C
4 D
4 N
5 E
6 F 
;
RUN;

proc sql;
  create table abmn as
    select 
      coalesce(ab.ID, mn.ID) as ID,
      coalesce(ab.Name, mn.Name) as Name,
      ifc(ab.ID ne . and mn.ID ne .,'Y','N') as flag 
    from ab full outer join mn 
    on ab.ID = mn.ID;
 /* on ab.ID = mn.ID and ab.Name = mn.Name; */
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Mar 2022 14:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804526#M316838</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-03-28T14:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging in SQL, want to write this code in sql: if (ab and mn) = 1 then flag = "Y"; el</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804552#M316842</link>
      <description>Thank you, its working and giving right output.&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Mar 2022 16:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-in-SQL-want-to-write-this-code-in-sql-if-a-and-b-1-then/m-p/804552#M316842</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2022-03-28T16:01:58Z</dc:date>
    </item>
  </channel>
</rss>

