<?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: help in proc sql code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674004#M202875</link>
    <description>&lt;P&gt;You have not show the expected results, so I hope next code will satisfy you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id date1 anydtdte10.;
format date1 yymmdd10.;
datalines;
1 2019-10-20
1 2019-10-23
1 2018-11-19
;
run;

data two;
input id date2 anydtdte10.;
format date2 yymmdd10.;
datalines;
1 2019-10-25
1 2019-11-10
1 2019-12-01
;
run;

proc sql;
create table three as
select coalesce(a.id,b.id) as ID, &lt;BR /&gt;       a.date1, b.date2 
   from one as a left join two as b
on a.id = b.id and
   b.date2 - a.date1 gt 4   
order by a.id,date1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;output result:&lt;/P&gt;
&lt;PRE&gt;Obs	ID date1	date2
1	1	2018-11-19	2019-12-01
2	1	2018-11-19	2019-11-10
3	1	2018-11-19	2019-10-25
4	1	2019-10-20	2019-11-10
5	1	2019-10-20	2019-10-25
6	1	2019-10-20	2019-12-01
7	1	2019-10-23	2019-12-01
8	1	2019-10-23	2019-11-10&lt;/PRE&gt;</description>
    <pubDate>Sun, 02 Aug 2020 18:09:57 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-08-02T18:09:57Z</dc:date>
    <item>
      <title>help in proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674000#M202873</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;Please suggest in my sql code. I am not getting the out put i need and&amp;nbsp; have warning messages in log&lt;/P&gt;
&lt;P&gt;I need to check every record in &lt;FONT color="#FF9900"&gt;one&lt;/FONT&gt; dataset with &lt;FONT color="#FF9900"&gt;two&lt;/FONT&gt; set by &lt;FONT color="#FF9900"&gt;id&lt;/FONT&gt; and check if &lt;FONT color="#FF9900"&gt;date2 -date1&lt;/FONT&gt; greater than 4 days&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;id date1 date2&lt;/P&gt;
&lt;P&gt;1 2018-11-19 2019-12-01&lt;BR /&gt;1 2019-10-20 2019-11-10&lt;BR /&gt;1 2019-10-20 2019-10-25&lt;BR /&gt;1 2019-10-20 2019-12-01&lt;BR /&gt;1 2019-10-23 2019-12-01&lt;BR /&gt;1 2019-10-23 2019-11-10&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;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id date1 $10.;
datalines;
1 2019-10-20
1 2019-10-23
1 2018-11-19
;
data two;
input id date2 $10.;
datalines;
1 2019-10-25
1 2019-11-10
1 2019-12-01
;


proc sql;
create table three as
select * from one as a left join two as b
on a.id=b.id
group by a.id,date1
having input(date2,yymmdd10.)- input(date1,yymmdd10.) gt 4;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Aug 2020 17:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674000#M202873</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-08-02T17:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: help in proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674004#M202875</link>
      <description>&lt;P&gt;You have not show the expected results, so I hope next code will satisfy you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id date1 anydtdte10.;
format date1 yymmdd10.;
datalines;
1 2019-10-20
1 2019-10-23
1 2018-11-19
;
run;

data two;
input id date2 anydtdte10.;
format date2 yymmdd10.;
datalines;
1 2019-10-25
1 2019-11-10
1 2019-12-01
;
run;

proc sql;
create table three as
select coalesce(a.id,b.id) as ID, &lt;BR /&gt;       a.date1, b.date2 
   from one as a left join two as b
on a.id = b.id and
   b.date2 - a.date1 gt 4   
order by a.id,date1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;output result:&lt;/P&gt;
&lt;PRE&gt;Obs	ID date1	date2
1	1	2018-11-19	2019-12-01
2	1	2018-11-19	2019-11-10
3	1	2018-11-19	2019-10-25
4	1	2019-10-20	2019-11-10
5	1	2019-10-20	2019-10-25
6	1	2019-10-20	2019-12-01
7	1	2019-10-23	2019-12-01
8	1	2019-10-23	2019-11-10&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Aug 2020 18:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674004#M202875</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-02T18:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: help in proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674071#M202922</link>
      <description>&lt;P&gt;For a.date = 2018-11-19, ALL dates in TWO satisfy your condition. Why do you keep only the last one, while for other dates you take three or two?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 08:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-proc-sql-code/m-p/674071#M202922</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-03T08:43:52Z</dc:date>
    </item>
  </channel>
</rss>

