<?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: Use IN= Data Option in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698465#M213624</link>
    <description>Tom, this is amazing!  Thank you so much!  I really wish I was better with SQL, but I haven't reached that point yet.  This worked perfectly.</description>
    <pubDate>Thu, 12 Nov 2020 18:23:05 GMT</pubDate>
    <dc:creator>djbateman</dc:creator>
    <dc:date>2020-11-12T18:23:05Z</dc:date>
    <item>
      <title>Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698411#M213589</link>
      <description>&lt;P&gt;I am merging two tables together by date ranges, so I have to use SQL to join them.&amp;nbsp; However, I want to use the IN= data set option to create additional flags in the data.&amp;nbsp; Is there an SQL equivalent to this method?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are two snippets of code.&amp;nbsp; The first one is what I am doing where I merge the 2 datasets by a date range.&amp;nbsp; But the second one is the concept I would like to incorporate into the SQL query.&amp;nbsp; I lose that in=a/in=b information once I leave SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table overlap as
	select a.*, b.aestdt, b.aeendt
	from cfuhosp as a left join ae as b
		on a.subject=b.subject
	where b.aestdt&amp;lt;=a.uhstdt&amp;lt;=b.aeendt
	order by subject;
quit;


data overlap;
	merge cfuhosp (in=a) ae (in=b);
	by ...; /* can't be done in data step */
	if a;
	if b=1 then discrep="Discrepancy Note #1";
	if b=0 then discrep="Discrepancy Note #2";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 15:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698411#M213589</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2020-11-12T15:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698416#M213594</link>
      <description>&lt;P&gt;When you do a LEFT join and the join does not find a match, then the variables from the "right" dataset will be missing. You can check for that.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 15:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698416#M213594</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-12T15:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698419#M213596</link>
      <description>&lt;P&gt;I don't think I have an issue with the join.&amp;nbsp; I just want to flag which part of the attached Venn diagram the observations fall in.&amp;nbsp; My SQL join is keeping data that fall in Area1 and Area3.&amp;nbsp; I want to create a flag that if the data is in Area1, then output one message; if the data is in Area3, then output a different message.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 15:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698419#M213596</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2020-11-12T15:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698426#M213600</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table overlap as
  select
    a.*,
    b.aestdt,
    b.aeendt,
    case
      when b.subject is missing
      then "Discrepancy Note #2"
      else "Discrepancy Note #1"
    end as discrep
  from cfuhosp as a left join ae as b
  on a.subject=b.subject
  where b.aestdt&amp;lt;=a.uhstdt&amp;lt;=b.aeendt
  order by subject
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is a re-engineering of your data step code in SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 16:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698426#M213600</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-12T16:08:16Z</dc:date>
    </item>
    <item>
      <title>KRe: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698436#M213607</link>
      <description>&lt;P&gt;Kurt,&lt;/P&gt;
&lt;P&gt;I believe your method will work, but I just realized a flaw in my logic.&amp;nbsp; All subjects in my CFUHOSP table are also in AE, so when using the case statement, it didn't give me 2 different notes.&amp;nbsp; To test, I went back to my AE dataset and deleted a subject.&amp;nbsp; Now that subject doesn't appear at all.&amp;nbsp; But this is because of my WHERE statement.&amp;nbsp; Since there are no AE start/end dates, the where condition is not satisfied for that subject to be retained.&amp;nbsp; I'll have to rethink how to handle these cases (because these are the ones that I want to retain).&amp;nbsp; But thank you for your help.&amp;nbsp; I think this will be a good place to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 16:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698436#M213607</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2020-11-12T16:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698445#M213610</link>
      <description>&lt;P&gt;No.&amp;nbsp; But you could test if one of the variables from the other table has a missing value.&amp;nbsp; Make sure to pick a variable where a missing value is not an expected value. Perhaps one of the key variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table overlap as
  select a.*
       , b.aestdt, b.aeendt
       , case when (missing(b.subject)) then "Discrepancy Note #2"
              else "Discrepancy Note #1"
         end as discrep
  from cfuhosp as a left join ae as b
    on a.subject=b.subject
    and b.aestdt&amp;lt;=a.uhstdt&amp;lt;=b.aeendt
  order by subject
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Nov 2020 17:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698445#M213610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-12T17:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698448#M213613</link>
      <description>&lt;P&gt;What &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;posted, you need to move the date condition into the ON clause. Should have seen that on my own.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 17:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698448#M213613</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-12T17:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Use IN= Data Option in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698465#M213624</link>
      <description>Tom, this is amazing!  Thank you so much!  I really wish I was better with SQL, but I haven't reached that point yet.  This worked perfectly.</description>
      <pubDate>Thu, 12 Nov 2020 18:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-IN-Data-Option-in-SQL/m-p/698465#M213624</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2020-11-12T18:23:05Z</dc:date>
    </item>
  </channel>
</rss>

