<?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: How to automate a date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411552#M100608</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152332"&gt;@Marwa_Se&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;thank you for ur help! i accepted Reeza's solution, it works good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thank you anyway!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;lol, actually you accepted your own answer but I appreciate it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2017 15:48:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-08T15:48:54Z</dc:date>
    <item>
      <title>How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411181#M100517</link>
      <description>&lt;P&gt;Hello everybody!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To automate a program, i need to update a set of data, so each month the date should be fixed every first friday of the current month,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, today we're on november 7, the program must be written this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data Tab_fin;

Set Tab_INIT;

where Date= '03NOV2017'd;

Run;&lt;/PRE&gt;&lt;P&gt;How can i automate the date, so i won't need to change it every month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let datej =%sysfunc(intnx(week.6,%sysfunc(intnx(MONTH,%sysfunc(today()),0)),1),DATE9.);

Data test_&amp;amp;datej;
set metiers ( keep=matricule dtmaj country salary code);
where  code='002' and dtmaj=&amp;amp;datej;
run;

&lt;/PRE&gt;&lt;P&gt;and i got this error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "DATEJ".&lt;/P&gt;&lt;P&gt;64 03NOV2017&lt;/P&gt;&lt;P&gt;-------&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=,&lt;/P&gt;&lt;P&gt;&amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, GE, GT, LE, LT, NE, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;65 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.TEST_03NOV2017 may be incomplete. When this step was stopped there&lt;/P&gt;&lt;P&gt;were 0 observations and 4 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.TEST_03NOV2017 was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.72 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.02 seconds&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;NOTE: Remote submit to SERVINF.SASBPU93 complete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me? &lt;img id="womanfrustrated" class="emoticon emoticon-womanfrustrated" src="https://communities.sas.com/i/smilies/16x16_woman-frustrated.png" alt="Woman Frustrated" title="Woman Frustrated" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 13:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411181#M100517</guid>
      <dc:creator>Marwa_Se</dc:creator>
      <dc:date>2017-11-07T13:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411194#M100521</link>
      <description>&lt;P&gt;Well, I would do it in two steps:&lt;/P&gt;
&lt;P&gt;1) get first day of month&lt;/P&gt;
&lt;P&gt;2) add days to get to friday&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;%let dt=12MAR2017;

data want;
  indt="&amp;amp;dt."d;
  /* Move indt to first of month */
  indt=intnx('month',indt,0,'b');
  /* Add days until Friday which is day 6*/
  /* Remove 1 day if its Saturday as this happens after Friday */
  if weekday(indt) then indt=indt-1;
  indt=indt + (6-day(indt));
  format indt date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Done it a bit long winded so you could see the workings.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 14:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411194#M100521</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-07T14:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411197#M100522</link>
      <description>&lt;P&gt;The INTNX function should be able to produce the first Friday of each month.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0syn64amroombn14vrdzksh459w.htm&amp;amp;locale=en#n1wbckrlffgb8jn15eebgjpqm23c" target="_blank"&gt;http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0syn64amroombn14vrdzksh459w.htm&amp;amp;locale=en#n1wbckrlffgb8jn15eebgjpqm23c&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 14:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411197#M100522</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-07T14:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411206#M100523</link>
      <description>&lt;P&gt;Despite the complexity of your formula, perhaps you have already found a way to retrieve the first Friday.&amp;nbsp; However, the problem lies in how you are using it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where code='002' and dtmaj=&amp;amp;datej;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro variable resolves, giving you this invalid SAS statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where code='002' and dtmaj=03NOV2017;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the only fix you need is to generate a n acceptable SAS statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where code='002' and dtmaj="&amp;amp;datej"d;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 14:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411206#M100523</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-07T14:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411215#M100525</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152332"&gt;@Marwa_Se&lt;/a&gt;, you had a syntax in your code and you asked for:&lt;/P&gt;
&lt;PRE&gt;To automate a program, i need to update a set of data, so each month the date should be fixed every first friday of the current month,&lt;/PRE&gt;
&lt;P&gt;For the 1st issue, see&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;answer.&lt;/P&gt;
&lt;P&gt;For the 2nd issue, I would make a slight change to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;posted code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  indt=today();                                 /* &amp;lt;&amp;lt;&amp;lt; get today's date &amp;gt;&amp;gt;&amp;gt; */
  /* Move indt to first of month */
  indt=intnx('month',indt,0,'b');
  /* Add days until Friday which is day 6*/
  /* Remove 1 day if its Saturday as this happens after Friday */
  if weekday(indt) then indt=indt-1;
  indt=indt + (6-day(indt));
  format indt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;then you don't need to supply the date each time before run.&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 15:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411215#M100525</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-07T15:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411227#M100528</link>
      <description>&lt;P&gt;Your main error is not using a date literal in the WHERE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where  code='002' and dtmaj="&amp;amp;datej"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I think your algorithm is off. What day to you want when the first of the month is a Friday?&amp;nbsp; Like it was in September 2017?&lt;/P&gt;
&lt;P&gt;Your current algorithm will yield result of 08SEP2017.&lt;/P&gt;
&lt;PRE&gt;556   %let today=20SEP2017;
557   %put &amp;amp;=today;
TODAY=20SEP2017
558   %let datej =%sysfunc(intnx(week.6,%sysfunc(intnx(MONTH,"&amp;amp;today"d,0)),1),DATE9.);
559   %put &amp;amp;=datej;
DATEJ=08SEP2017&lt;/PRE&gt;
&lt;P&gt;So you could subtract one from the first day of the month.&lt;/P&gt;
&lt;PRE&gt;561   %let datej =%sysfunc(intnx(week.6,%sysfunc(intnx(MONTH,"&amp;amp;today"d,0))-1,1),DATE9.);
562   %put &amp;amp;=datej ;
DATEJ=01SEP2017 &lt;/PRE&gt;
&lt;P&gt;Or find the last day of the previous month.&lt;/P&gt;
&lt;PRE&gt;564   %let datej =%sysfunc(intnx(week.6,%sysfunc(intnx(MONTH,"&amp;amp;today"d,-1,e)),1),DATE9.);
565   %put &amp;amp;=datej ;
DATEJ=01SEP2017 &lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411227#M100528</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-07T16:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411241#M100531</link>
      <description>&lt;P&gt;Use NWKDOM instead.&lt;/P&gt;
&lt;H1 id="p1kdveu0ry8ltxn1m3um2ntxs7d5" class="xis-title"&gt;NWKDOM Function&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Returns the date for the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;n&lt;/SPAN&gt;th occurrence of a weekday for the specified month and year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Tab_fin;

Set Tab_INIT;

where Date= NWKDOM(1, 6, month(today)), year(today()) );

Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411241#M100531</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-07T16:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411439#M100586</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;thank you for your answer i tried ur code but it gives me 6 october in spite of 3 november&lt;/P&gt;&lt;P&gt;and even though i change the month it gives me everytime the six day of every month :s&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 07:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411439#M100586</guid>
      <dc:creator>Marwa_Se</dc:creator>
      <dc:date>2017-11-08T07:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411440#M100587</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;it works perfectly!! thank you so much!!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 07:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411440#M100587</guid>
      <dc:creator>Marwa_Se</dc:creator>
      <dc:date>2017-11-08T07:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411441#M100588</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;thank you for ur help! i accepted Reeza's solution, it works good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thank you anyway!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 07:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411441#M100588</guid>
      <dc:creator>Marwa_Se</dc:creator>
      <dc:date>2017-11-08T07:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411552#M100608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152332"&gt;@Marwa_Se&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;thank you for ur help! i accepted Reeza's solution, it works good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thank you anyway!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;lol, actually you accepted your own answer but I appreciate it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 15:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-a-date/m-p/411552#M100608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-08T15:48:54Z</dc:date>
    </item>
  </channel>
</rss>

