<?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 last 5 weeks data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882935#M348862</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, the TX_DT variable is a numeric data type in the dataset which is displayed as '2023-05-22' and so on. When I tried your suggested code, it is not producing any records. Could you please suggest me any corrections?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2023 13:45:37 GMT</pubDate>
    <dc:creator>hk24</dc:creator>
    <dc:date>2023-06-29T13:45:37Z</dc:date>
    <item>
      <title>Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882930#M348858</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset available at a daily level, with the date column called 'TX_DT' in the format yyyy-mm-dd. I want to limit the data pull to only last 5 weeks. Irrespective of the current date, I would want to extract the data for its previous 5 weeks. For example, if today is 06-29-2023, I want the data from 05-22-2023 until 06-25-2023. In the data my week starts from Monday and ends on Sunday. Similarly, if today was 07-04-2023, I would like the data from 05-29-2023 until 07-02-2023.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using intnx function with the code below but I'm not getting any result.&lt;/P&gt;&lt;PRE&gt;data final;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set temp(where=(intnx('dtweek', TX_DT, -5, 'B') = intnx('dtweek', datetime(), 0, 'B')));&lt;BR /&gt;run;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; Can someone please help me with the code?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882930#M348858</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T13:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882932#M348859</link>
      <description>&lt;P&gt;You want to extract data from between two dates, but nothing you have written checks to see if the date is between these two dates. You don't show your data, so perhaps this is what you want (but really I'm guessing with seeing your data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
    set temp(where=(intnx('week.1', TX_DT, -5, 'B') &amp;lt;= tx_dt &amp;lt;= intnx('week.1', datetime(), 0, 'B')));
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I am using&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'week.1'&lt;/FONT&gt;&amp;nbsp;because you said you want weeks to start on Mondays.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882932#M348859</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-29T13:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882933#M348860</link>
      <description>&lt;P&gt;Why are you using DTWEEK interval if your variable is a DATE?&lt;/P&gt;
&lt;P&gt;Is your TX_DT variable really a DATETIME variable instead of a DATE variable?&amp;nbsp; What format does it have attached to it?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882933#M348860</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T13:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882934#M348861</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, when I checked the data type of TX_DT variable, it seems to be numeric and neither date nor datetime data type. Could you please suggest me a solution?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882934#M348861</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T13:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882935#M348862</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, the TX_DT variable is a numeric data type in the dataset which is displayed as '2023-05-22' and so on. When I tried your suggested code, it is not producing any records. Could you please suggest me any corrections?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882935#M348862</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T13:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882936#M348863</link>
      <description>&lt;P&gt;If it has no format attached then what actual values does it have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some possibilities&amp;nbsp;&lt;/P&gt;
&lt;P&gt;23,190&amp;nbsp; - Actual date value&lt;/P&gt;
&lt;P&gt;20,230,629 - Integer that a human might think is in YYYYMMDD style&lt;/P&gt;
&lt;P&gt;2,003,651,033 - Actual datetime value&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;180  data _null_;
181    today=date();
182    now=datetime();
183    put today=comma20. today=date9. today=yymmddn8. ;
184    put now=comma20. now=datetime19. ;
185  run;

today=23,190 today=29JUN2023 today=20230629
now=2,003,651,033 now=29JUN2023:09:43:53
&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882936#M348863</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T13:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882937#M348864</link>
      <description>&lt;P&gt;A number cannot display with dashes in it unless there is a FORMAT attached to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run PROC CONTENTS on the dataset and see what format specification is attached to the variable.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882937#M348864</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T13:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882938#M348865</link>
      <description>&lt;P&gt;The variable displays value as 'YYYY-MM-DD', i.e., 2023-05-22 and so on. Not sure what format you are asking for.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 13:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882938#M348865</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T13:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882939#M348866</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438012"&gt;@hk24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, the TX_DT variable is a numeric data type in the dataset which is displayed as '2023-05-22' and so on. When I tried your suggested code, it is not producing any records. Could you please suggest me any corrections?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As I said earlier, I am guessing because you have not shown us the data. It is ALWAYS a good idea to show us a portion of the data following these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions and examples&lt;/A&gt;. Next time,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438012"&gt;@hk24&lt;/a&gt;&amp;nbsp;, we will expect to see a portion of the data as described. Do not make us ask again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please run PROC CONTENTS and report what it says for TX_DT.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 14:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882939#M348866</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-29T14:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882940#M348867</link>
      <description>&lt;P&gt;Check the variable's metadata (type,length,format,label,etc).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=temp;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check the actual range of the unformatted values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=temp min max range ;
  var tx_dt;
  format tx_dt ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2023 14:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882940#M348867</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T14:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882941#M348868</link>
      <description>Okay, thanks for clarifying it. I checked it and the 'Type' shows as Num with its 'Format' as YYMMDD10.</description>
      <pubDate>Thu, 29 Jun 2023 14:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882941#M348868</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T14:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882942#M348869</link>
      <description>&lt;P&gt;So you have a DATE values.&amp;nbsp; You will want to use the WEEK interval (or probably the WEEK.1 interval to start on Monday instead of Sunday)&amp;nbsp; You will want to use the DATE() function (or it's alias TODAY()) to get the current date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you want the data that is newer than 5 weeks ago.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
    set temp;
    where intnx('week.1', today(), -5, 'B') &amp;lt;= TX_DT ;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2023 14:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882942#M348869</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T14:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882943#M348870</link>
      <description>Thank you so much! Just wanted to quickly understand the 'week.1' part as the above code is extracting the values from 05-21-2023 (Sunday) instead of 05-22-2023 (Monday) and when I changed it 'week.2' in the code, it is extracting the values from 05-22-2023 (Monday). Why would this happen?</description>
      <pubDate>Thu, 29 Jun 2023 14:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882943#M348870</guid>
      <dc:creator>hk24</dc:creator>
      <dc:date>2023-06-29T14:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extract last 5 weeks data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882945#M348871</link>
      <description>&lt;P&gt;Sunday is day 1.&amp;nbsp; So week.1 and week are the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 14:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-last-5-weeks-data/m-p/882945#M348871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T14:21:17Z</dc:date>
    </item>
  </channel>
</rss>

