<?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: Proc Sql Date logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592312#M169817</link>
    <description>&lt;P&gt;If you had posted your SQL earlier, we would have arrived at this solution sooner; by only showing a short snippet of what you were actually doing you made it harder for us to understand the situation.&lt;/P&gt;
&lt;P&gt;Always post whole steps, and complete logs of whole steps to enable rapid diagnosing. Supplying example data in usable form (data steps with datalines) is also essential in getting good answers quickly.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2019 20:22:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-09-27T20:22:53Z</dc:date>
    <item>
      <title>Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592287#M169805</link>
      <description>&lt;P&gt;I have a table with a Date stanp formatted as 'MM-DD-YYYY' (5-23-2017 for example)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use the PROC SQL to get the upcoming Saturday following this date. so that For May 21-26th, the date would be returned as 5-27-2017.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or Sept 22 - Sept 27 2019 would return as Sept 28 2019.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying different code variations but just cant get it. TIA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 19:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592287#M169805</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2019-09-27T19:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592289#M169807</link>
      <description>&lt;P&gt;Since SAS considers Saturday the last day of the week, use this function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('week',your_date,0,'e')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Sep 2019 19:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592289#M169807</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-27T19:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592290#M169808</link>
      <description>&lt;P&gt;What is the type of your variable?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming it's a SAS date, numeric with a date format, then you can use INTNX().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; intnx('week', date_variable, 0, 'e') as next_saturday
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to factor in holidays and such this will not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table with a Date stanp formatted as 'MM-DD-YYYY' (5-23-2017 for example)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use the PROC SQL to get the upcoming Saturday following this date. so that For May 21-26th, the date would be returned as 5-27-2017.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or Sept 22 - Sept 27 2019 would return as Sept 28 2019.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been trying different code variations but just cant get it. TIA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 19:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592290#M169808</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-27T19:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592291#M169809</link>
      <description>&lt;P&gt;Use &lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0ahi8tk3trkv5n173sil9hd7c62.htm&amp;amp;locale=en" target="_self"&gt;WEEKDAY()&lt;/A&gt; to get the day of the week, then add the appropriate number of days to get to Saturday.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datevariable+7-weekday(datevariable)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Sep 2019 19:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592291#M169809</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-27T19:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592300#M169811</link>
      <description>my response date is formatted as such when I pull the data in SAS:&lt;BR /&gt;&lt;BR /&gt;REPORT_DATE&lt;BR /&gt;28JAN2019&lt;BR /&gt;&lt;BR /&gt;when I use the following syntax:&lt;BR /&gt;datepart(intnx('week',REPORT_DATE,0,'e')) format = date9. as END_DT&lt;BR /&gt;&lt;BR /&gt;I end up with 01JAN1960 (starting point)&lt;BR /&gt;without the datepart i get a numeric 21582</description>
      <pubDate>Fri, 27 Sep 2019 19:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592300#M169811</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2019-09-27T19:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592302#M169812</link>
      <description>&lt;P&gt;DATEPART() is applied on the original variable before you use INTNX(), but you're passing a datetime to INTNX with the interval set for a date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apply DATEPART() within INTNX() not after.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;my response date is formatted as such when I pull the data in SAS:&lt;BR /&gt;&lt;BR /&gt;REPORT_DATE&lt;BR /&gt;28JAN2019&lt;BR /&gt;&lt;BR /&gt;when I use the following syntax:&lt;BR /&gt;datepart(intnx('week',REPORT_DATE,0,'e')) format = date9. as END_DT&lt;BR /&gt;&lt;BR /&gt;I end up with 01JAN1960 (starting point)&lt;BR /&gt;without the datepart i get a numeric 21582&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 19:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592302#M169812</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-27T19:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592307#M169813</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263957"&gt;@Jyuen204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;my response date is formatted as such when I pull the data in SAS:&lt;BR /&gt;&lt;BR /&gt;REPORT_DATE&lt;BR /&gt;28JAN2019&lt;BR /&gt;&lt;BR /&gt;when I use the following syntax:&lt;BR /&gt;datepart(intnx('week',REPORT_DATE,0,'e')) format = date9. as END_DT&lt;BR /&gt;&lt;BR /&gt;I end up with 01JAN1960 (starting point)&lt;BR /&gt;without the datepart i get a numeric 21582&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why are you using datepart() on a date? datepart() is used to extract the date out of a datetime. 21582 is just the count of days from 1960-01-01, so this is correct. You just need to apply a date format to the new variable so it becomes human-readable.&lt;/P&gt;
&lt;P&gt;I recommend that you study the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lrcon&amp;amp;docsetTarget=n0q9ylcaccjgjrn19hvqnd9cte8p.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;chapter on dates and times in SAS Language Concepts&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 20:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592307#M169813</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-27T20:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592308#M169814</link>
      <description>&lt;P&gt;datepart(REPORT_DATE) format = date9. as REPORT_DATE,&lt;BR /&gt;intnx('week',(datepart(REPORT_DATE) format = date9.),0,'e') as END_DT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i get a syntax error pulling this way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the REPORT_DATE when converting to date9.&amp;nbsp; fine&lt;/P&gt;&lt;P&gt;but using the intnx, i get a syntax error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 20:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592308#M169814</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2019-09-27T20:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592310#M169815</link>
      <description>&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('week',calculated REPORT_DATE,0,'e') format = date9. as END_DT&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Sep 2019 20:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592310#M169815</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-27T20:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592311#M169816</link>
      <description>&lt;P&gt;Thank you thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 20:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592311#M169816</guid>
      <dc:creator>Jyuen204</dc:creator>
      <dc:date>2019-09-27T20:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592312#M169817</link>
      <description>&lt;P&gt;If you had posted your SQL earlier, we would have arrived at this solution sooner; by only showing a short snippet of what you were actually doing you made it harder for us to understand the situation.&lt;/P&gt;
&lt;P&gt;Always post whole steps, and complete logs of whole steps to enable rapid diagnosing. Supplying example data in usable form (data steps with datalines) is also essential in getting good answers quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 20:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592312#M169817</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-27T20:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Date logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592317#M169818</link>
      <description>Or just this:&lt;BR /&gt;&lt;BR /&gt;intnx('week',datepart(REPORT_DATE),0,'e') as END_DT</description>
      <pubDate>Fri, 27 Sep 2019 20:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Date-logic/m-p/592317#M169818</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-27T20:35:19Z</dc:date>
    </item>
  </channel>
</rss>

