<?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: Learning PROC SQL Equivalent in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548559#M152114</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269362"&gt;@SASLearner7&lt;/a&gt;&amp;nbsp; &amp;nbsp;Proc sql isn't convenient but if that's what you want--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Your samples*/
data pets1;

a = 2015; b='boxer'; c='123xyz'; addr='a'; output;

a = 2016; b='cat'; c='5687abc'; addr='b'; output;

a = 2018; b='dog'; c='123abc'; addr='a'; output;

a = 2011; b='cat'; c='5687abc'; addr='b'; output;

run;

data pets2;

a = 2018; b='dog'; c='135abc'; addr='a'; output;

a = 2011; b='cat'; c='5837abc'; addr='b'; output;

a = 2015; b='fly'; c='1234xyz'; addr='a'; output;

a = 2016; b='cat'; c='5687abc'; addr='b'; output;

a = 2014; b='cat'; c='5837abc'; addr='b'; output;

a = 2015; b='fly'; c='1234xyz'; addr='a'; output;

run;

/*Using Sort and Merge*/
proc sort data=pets1;
by a b;
run;

proc sort data=pets2;
by a b;
run;

data A3;

   merge pets1 (in=in1) pets2 (in=in2);

   by a b;

   length s $10;

   if in1 and in2

      then s= 'both';

   else if in1

      then s= 'pets1';

   else if in2

      then s= 'pets2';

run;

/*Using Proc sql*/

proc sql;
create table a3__ as
select coalesce(a.a,b.a) as a,coalesce(a.b,b.b) as b,coalesce(a.c,b.c) as c, coalesce(a.addr,b.addr) as addr,
case when a.a=b.a and a.b=b.b   then  'both' 
when a.a&amp;gt;. then 'Pets1'
when b.a&amp;gt;. then 'pets2' else ' ' end as s
from pets1 a full join pets2 b
on a.a=b.a and a.b=b.b;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Apr 2019 16:51:34 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-04-04T16:51:34Z</dc:date>
    <item>
      <title>Learning PROC SQL Equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548538#M152103</link>
      <description>&lt;P&gt;I am trying to learn how to use PROC SQL.&amp;nbsp; I am trying to figure out how to completely use PROC SQL to do the same logic and have the same output dataset as the code below.&amp;nbsp; Pets1 and Pets2 datasets are both really wide and long so I try to subset the data before merging.&amp;nbsp; I'm hoping I can accomplish the same using purely PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;noprint&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a, b, c&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by &lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;a, b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a, b&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by &lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;a, b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp1 (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=A) temp2 (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=B);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; length&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A and B&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'both'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'temp1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; B&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'temp2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 15:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548538#M152103</guid>
      <dc:creator>SASLearner7</dc:creator>
      <dc:date>2019-04-04T15:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Learning PROC SQL Equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548540#M152104</link>
      <description>&lt;P&gt;Could you post sample data for us to work with plz?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 15:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548540#M152104</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T15:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Learning PROC SQL Equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548548#M152108</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269362"&gt;@SASLearner7&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to learn how to use PROC SQL.&amp;nbsp; I am trying to figure out how to completely use PROC SQL to do the same logic and have the same output dataset as the code below.&amp;nbsp; Pets1 and Pets2 datasets are both really wide and long so I try to subset the data before merging.&amp;nbsp; I'm hoping I can accomplish the same using purely PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;noprint&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a, b, c&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by &lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;a, b;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a, b&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by &lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;a, b;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp1 (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=A) temp2 (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=B);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a b;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; length&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp; if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A and B&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'both'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'temp1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; B&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; s= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'temp2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Example data.&lt;/P&gt;
&lt;P&gt;Describe what the actual intent of your code is. Without data I can't tell what your result actually may be.&lt;/P&gt;
&lt;P&gt;And there are somethings the data step does that are much more complex (read possibly requiring either multiple&amp;nbsp; temporary data sets or subqueries and complex joins) in Proc SQL and vice versa. Note that the way Proc SQL used variables with the same name that you need to explicitly write COALESCE,r COALESCEC or case statements &amp;nbsp;code to do what Merge does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance in your pets data sets are the values combinations of A and B variables repeated? Different or same numbers of repeats between the two sets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Poor idea to use BY variables and name the IN= variables with the same name. Are you sure your data step works as intended?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 16:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548548#M152108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-04T16:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Learning PROC SQL Equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548549#M152109</link>
      <description>&lt;P&gt;Variables a and b are composite keys which are unique for each record&amp;nbsp;for pets1 and pets2.&amp;nbsp; I am&amp;nbsp;trying to figure out how to do it within the confines of PROC SQL syntax since it's different from DATA STEP syntax.&amp;nbsp; For my example, I am trying to figure out if any records in pets1 appears in pets2, and vice versa, or if they appear on datasets.&amp;nbsp; Hopefully that makes sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'boxer'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'123xyz'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2016&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'cat'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'5687abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'b'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2018&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'dog'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'123abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2011&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'cat'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'5687abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'b'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; pets2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2018&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'dog'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'135abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2011&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'cat'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'5837abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'b'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'fly'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'1234xyz'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2016&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'cat'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'5687abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'b'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2014&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'cat'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'5837abc'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'b'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;a = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; b=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'fly'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; c=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'1234xyz'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; addr=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 16:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548549#M152109</guid>
      <dc:creator>SASLearner7</dc:creator>
      <dc:date>2019-04-04T16:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Learning PROC SQL Equivalent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548559#M152114</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269362"&gt;@SASLearner7&lt;/a&gt;&amp;nbsp; &amp;nbsp;Proc sql isn't convenient but if that's what you want--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Your samples*/
data pets1;

a = 2015; b='boxer'; c='123xyz'; addr='a'; output;

a = 2016; b='cat'; c='5687abc'; addr='b'; output;

a = 2018; b='dog'; c='123abc'; addr='a'; output;

a = 2011; b='cat'; c='5687abc'; addr='b'; output;

run;

data pets2;

a = 2018; b='dog'; c='135abc'; addr='a'; output;

a = 2011; b='cat'; c='5837abc'; addr='b'; output;

a = 2015; b='fly'; c='1234xyz'; addr='a'; output;

a = 2016; b='cat'; c='5687abc'; addr='b'; output;

a = 2014; b='cat'; c='5837abc'; addr='b'; output;

a = 2015; b='fly'; c='1234xyz'; addr='a'; output;

run;

/*Using Sort and Merge*/
proc sort data=pets1;
by a b;
run;

proc sort data=pets2;
by a b;
run;

data A3;

   merge pets1 (in=in1) pets2 (in=in2);

   by a b;

   length s $10;

   if in1 and in2

      then s= 'both';

   else if in1

      then s= 'pets1';

   else if in2

      then s= 'pets2';

run;

/*Using Proc sql*/

proc sql;
create table a3__ as
select coalesce(a.a,b.a) as a,coalesce(a.b,b.b) as b,coalesce(a.c,b.c) as c, coalesce(a.addr,b.addr) as addr,
case when a.a=b.a and a.b=b.b   then  'both' 
when a.a&amp;gt;. then 'Pets1'
when b.a&amp;gt;. then 'pets2' else ' ' end as s
from pets1 a full join pets2 b
on a.a=b.a and a.b=b.b;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 16:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-PROC-SQL-Equivalent/m-p/548559#M152114</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T16:51:34Z</dc:date>
    </item>
  </channel>
</rss>

