<?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 Determining date difference in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470264#M120381</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want to code the following&lt;/P&gt;
&lt;P&gt;assume i have a data set which contains time series date, product id and launch date if the difference between the launch date and date is more than 6 month, we should consider the history of that product and take all records for analysis, else ignore the product.&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Product id&lt;/TD&gt;
&lt;TD&gt;date&lt;/TD&gt;
&lt;TD&gt;launch date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;201711&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;201712&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;201801&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;201802&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;201710&lt;/TD&gt;
&lt;TD&gt;201706&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;201711&lt;/TD&gt;
&lt;TD&gt;201706&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;201712&lt;/TD&gt;
&lt;TD&gt;201706&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;201801&lt;/TD&gt;
&lt;TD&gt;201706&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;201802&lt;/TD&gt;
&lt;TD&gt;201706&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above since product 1 was launched in 201710, and it is not 6 month old, we should ignore the history of this product, while product 2 is already 6 month old now hence we should consider this product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jun 2018 11:59:40 GMT</pubDate>
    <dc:creator>kamlesh_suthar</dc:creator>
    <dc:date>2018-06-14T11:59:40Z</dc:date>
    <item>
      <title>Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470264#M120381</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want to code the following&lt;/P&gt;
&lt;P&gt;assume i have a data set which contains time series date, product id and launch date if the difference between the launch date and date is more than 6 month, we should consider the history of that product and take all records for analysis, else ignore the product.&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt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t;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above since product 1 was launched in 201710, and it is not 6 month old, we should ignore the history of this product, while product 2 is already 6 month old now hence we should consider this product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 11:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470264#M120381</guid>
      <dc:creator>kamlesh_suthar</dc:creator>
      <dc:date>2018-06-14T11:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470265#M120382</link>
      <description>&lt;P&gt;You can use the INTCK function, something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if intck(launchdate,date)&amp;gt;6 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 11:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470265#M120382</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-14T11:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470268#M120385</link>
      <description>&lt;P&gt;You posted this question in the "Base SAS Programming" community. Do you think that "base sas" (sic) is a descriptive subject (what you were asked for when hitting the submit button)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please be a little more creative next time around.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will edit the subject of your initial post and the answers.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 11:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470268#M120385</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-14T11:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470269#M120386</link>
      <description>&lt;P&gt;Not tested, post test data in the form of a datastep!&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select *
  from   have
  where product_id in (select distinct product_id from have where intck('year',launch_date,date) &amp;lt;=6);
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 12:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470269#M120386</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-14T12:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470394#M120397</link>
      <description>&lt;P&gt;Convert the dates to SAS dates and use function intck to calculate the number of months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product _date _ldate;
date = mdy(mod(_date,100),1,floor(_date/100));
ldate = mdy(mod(_ldate,100),1,floor(_ldate/100));
drop _: ;
format date ldate yymmdd10.;
datalines; 
1 201710 201710 
1 201711 201710 
1 201712 201710 
1 201801 201710 
1 201802 201710 
2 201710 201706 
2 201711 201706 
2 201712 201706 
2 201801 201706 
2 201802 201706 
;

proc sql;
create table want as
select
    product,
    date,
    ldate
from
    have
group by product
having intck("month",min(ldate), max(date), "continuous") &amp;gt; 6;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 17:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470394#M120397</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-14T17:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Determining date difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470774#M120489</link>
      <description>&lt;P&gt;To build on PGStats' response, the article&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html" target="_self"&gt;"INTCK and INTNX: Two essential functions for computing intervals between dates in SAS"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;contains more information, discussion, and an example of using the INTCK function and the 'CONTINUOUS' option.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jun 2018 10:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-date-difference/m-p/470774#M120489</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-06-16T10:44:35Z</dc:date>
    </item>
  </channel>
</rss>

