<?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: Extract records 6 months prior to a date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-records-6-months-prior-to-a-date/m-p/644629#M192570</link>
    <description>&lt;P&gt;You may want to examine the dates that the month difference changes in the below code. Month1 does not use the 'C' option in intck and Month2 does.&lt;/P&gt;
&lt;PRE&gt;data example;
   do date = '31DEC2018'd to '01Jul2019'd;
      months1 = intck('month',date,'01Jul2019'd);
      months2 = intck('month',date,'01Jul2019'd,'C');
      output;
   end;
   format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;It may be all you need to do is drop the 'C' from intck function call.&lt;/P&gt;</description>
    <pubDate>Fri, 01 May 2020 22:33:47 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-05-01T22:33:47Z</dc:date>
    <item>
      <title>Extract records 6 months prior to a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-records-6-months-prior-to-a-date/m-p/644605#M192564</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a masterlist with 2 years of data... I need to segment data for some months and check it against the last 6 or 12 months of activity to mark how many are repeats vs net new&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i have so far is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isolate the month i want. the list has a variable run_date which has the 1st day of a month as the run date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So jan = 1/1/2019&lt;/P&gt;&lt;P&gt;feb = 2/1/2019&lt;/P&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE REPEAT_MONTH AS&lt;BR /&gt;SELECT *,CASE WHEN COUNT(BAN) &amp;gt;1 THEN 'REPEAT'&lt;BR /&gt;ELSE 'SINGLE'&lt;BR /&gt;END AS REPS_IN_MONTH&lt;BR /&gt;FROM MASTER&lt;BR /&gt;WHERE RUN_DATE ='01Jul2019'd&lt;BR /&gt;GROUP BY ID&lt;BR /&gt;ORDER BY ID&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;PROC SORT DATA=REPEAT_MONTH nodupkey;by ban;quit;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;left join to the master table for the months i need to check against. in this case i need data from Jan 2019 to jun 2019, that is 6 months before run date specified above&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE historical&amp;nbsp; AS&lt;BR /&gt;SELECT&amp;nbsp; A.*,B.RUN_DATE AS REPEAT_DATE,COUNT(A.BAN) AS COUNT,&lt;BR /&gt;CASE WHEN COUNT(A.BAN) &amp;gt;1 THEN 'REPEAT'&lt;BR /&gt;ELSE 'NEW'&lt;BR /&gt;END&amp;nbsp; AS IN_6M&lt;BR /&gt;FROM REPEAT_MONTH A LEFT JOIN MASTER B&lt;BR /&gt;ON A.id=B.id&lt;BR /&gt;where 1 &amp;lt;= intck('month',b.run_date,a.run_Date,'c') &amp;lt;=6&lt;BR /&gt;GROUP BY A.id&lt;BR /&gt;ORDER BY A.BAN,B.RUN_Date&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;doesn't give me the same yield as where b.run_date between '01jan2019'd and '01jun2019'd. what am i doing wrong. appreciate any thoughts on making any of this more efficient.&lt;/DIV&gt;&lt;DIV&gt;Masterlist contains data from 2018 jan to 2020 mar. I'd like to run this for multiple months &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you kindly&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 May 2020 21:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-records-6-months-prior-to-a-date/m-p/644605#M192564</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-05-01T21:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract records 6 months prior to a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-records-6-months-prior-to-a-date/m-p/644629#M192570</link>
      <description>&lt;P&gt;You may want to examine the dates that the month difference changes in the below code. Month1 does not use the 'C' option in intck and Month2 does.&lt;/P&gt;
&lt;PRE&gt;data example;
   do date = '31DEC2018'd to '01Jul2019'd;
      months1 = intck('month',date,'01Jul2019'd);
      months2 = intck('month',date,'01Jul2019'd,'C');
      output;
   end;
   format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;It may be all you need to do is drop the 'C' from intck function call.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 22:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-records-6-months-prior-to-a-date/m-p/644629#M192570</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-01T22:33:47Z</dc:date>
    </item>
  </channel>
</rss>

