<?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: Filtering based on Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568069#M159840</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278143"&gt;@Xing&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;if the date is stored in a variable and I want to see 1 year prior to each date in this variable, what should I do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you asking "Given a specific date such as 21JUN2019, how do I get a SAS date value that is the same date one year ago?".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newdate = intnx('year',date,-1,'same');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if that is not what you want you need to provide a much more concrete example such as with actual dates and the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really should look at this: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jun 2019 20:24:24 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-06-21T20:24:24Z</dc:date>
    <item>
      <title>Filtering based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568001#M159810</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input admdate : mmddyy10. id @@;
	format admdate mmddyy10.;
	cards;
05/01/2009 1
08/01/2010 2
07/01/2012 3
08/24/2007 4
12/11/2012 5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Currently, I have a dataset with date and id. I want to select all the observations that the date is within 1 year prior to 1/1/2013. That is I want to select all the obs with the date between 1/1/2012 and 1/1/2013. What should I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 17:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568001#M159810</guid>
      <dc:creator>Xing</dc:creator>
      <dc:date>2019-06-21T17:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568011#M159814</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test;
	where '01jan2012'd &amp;lt;= admdate &amp;lt;= '01jan2013'd;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 17:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568011#M159814</guid>
      <dc:creator>derekg</dc:creator>
      <dc:date>2019-06-21T17:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568013#M159815</link>
      <description>&lt;P&gt;Here are three ways that may work. They may need adjusting a little depending on whether the dates you mentioned as boundaries should be included or not.&lt;/P&gt;
&lt;PRE&gt;data want;
   set test;
   /* between to specified dates*/
   where '01JAN2012'd le admdate lt '01JAN2013'd;
run;
data want2;
   set test;
   /* within a specified year*/
   where year(admdate) = 2012;
run;
data want3;
   set test;
   /* "year" as in from date*/
   where intck('year',admdate,'01JAN2013'd,'c') = 0;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Important: Any time you want to use a literal data is has to be in either DATE9. or DATE7. format, in quotes, with the D immediately following to tell SAS the value is a date literal value.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 18:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568013#M159815</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-21T18:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568019#M159817</link>
      <description>&lt;P&gt;if the date is stored in a variable and I want to see 1 year prior to each date in this variable, what should I do?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 18:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568019#M159817</guid>
      <dc:creator>Xing</dc:creator>
      <dc:date>2019-06-21T18:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568069#M159840</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278143"&gt;@Xing&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;if the date is stored in a variable and I want to see 1 year prior to each date in this variable, what should I do?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you asking "Given a specific date such as 21JUN2019, how do I get a SAS date value that is the same date one year ago?".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newdate = intnx('year',date,-1,'same');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if that is not what you want you need to provide a much more concrete example such as with actual dates and the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really should look at this: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 20:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-based-on-Date/m-p/568069#M159840</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-21T20:24:24Z</dc:date>
    </item>
  </channel>
</rss>

