<?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: intervalds not working in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584610#M166540</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272389"&gt;@danteploy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the following code for generating date intervals.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options intervalds=(BankingDays=work.BankDayDS);&lt;BR /&gt;data BankDayDS (keep=BEGIN );&lt;BR /&gt;start = '01DEC2018'D;&lt;BR /&gt;stop = '01JAN2030'D;&lt;BR /&gt;nwkdays = INTCK('WEEKDAY',start,stop);&lt;BR /&gt;do i = 0 to nwkdays;&lt;BR /&gt;BEGIN = INTNX('WEEKDAY',start,i);&lt;BR /&gt;BEGIN_PERIOD = INTNX('WEEKDAY',start,i);&lt;BR /&gt;year = YEAR(BEGIN);&lt;BR /&gt;if BEGIN ne HOLIDAY('NEWYEAR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MLK',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USPRESIDENTS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MEMORIAL',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USINDEPENDENCE',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('LABOR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('VETERANS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('THANKSGIVING',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('CHRISTMAS',year) then&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;format BEGIN DATE.;&lt;BR /&gt;format BEGIN_PERIOD MONYY.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works when I use it in intnx or intck in a data step.&amp;nbsp; But when I try to use it inside a macro, I get, "WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options minoperator;&lt;BR /&gt;%macro velocity()/mindelimiter=',';&lt;/P&gt;
&lt;P&gt;/*** Cycle through week one workday at a time ***/&lt;BR /&gt;%let first_date = %sysfunc(inputn(01JAN2019,date9.));&lt;BR /&gt;/*%sysfunc(intnx(month, %sysfunc(today()), -1,b)); */&lt;BR /&gt;%let end_date = %sysfunc(inputn(01APR2019,date9.));&lt;BR /&gt;%let i = 1;&lt;/P&gt;
&lt;P&gt;%put first_date = &amp;amp;first_date.;&lt;/P&gt;
&lt;P&gt;%do %while(&amp;amp;first_date. &amp;lt; &amp;amp;end_date.);&lt;/P&gt;
&lt;P&gt;%put first_date = &amp;amp;first_date;&lt;BR /&gt;%let year1 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, -4), year.);&lt;BR /&gt;%let year2 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, 0), year.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another option I need to use to get this to work?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use a data step to create the macro variables? You don't show how you are using the macro variables so I can't tell if you actually need a completely macro solution.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   sd = '23JUN2020'd;
   nd = intnx('BankingDays',sd,4);
   call symputx('mvar',nd);
run;

%put mvar is: &amp;amp;mvar.;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Aug 2019 15:26:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-28T15:26:50Z</dc:date>
    <item>
      <title>intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584566#M166523</link>
      <description>&lt;P&gt;I have the following code for generating date intervals.&amp;nbsp;&lt;/P&gt;&lt;P&gt;options intervalds=(BankingDays=work.BankDayDS);&lt;BR /&gt;data BankDayDS (keep=BEGIN );&lt;BR /&gt;start = '01DEC2018'D;&lt;BR /&gt;stop = '01JAN2030'D;&lt;BR /&gt;nwkdays = INTCK('WEEKDAY',start,stop);&lt;BR /&gt;do i = 0 to nwkdays;&lt;BR /&gt;BEGIN = INTNX('WEEKDAY',start,i);&lt;BR /&gt;BEGIN_PERIOD = INTNX('WEEKDAY',start,i);&lt;BR /&gt;year = YEAR(BEGIN);&lt;BR /&gt;if BEGIN ne HOLIDAY('NEWYEAR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MLK',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USPRESIDENTS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MEMORIAL',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USINDEPENDENCE',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('LABOR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('VETERANS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('THANKSGIVING',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('CHRISTMAS',year) then&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;format BEGIN DATE.;&lt;BR /&gt;format BEGIN_PERIOD MONYY.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works when I use it in intnx or intck in a data step.&amp;nbsp; But when I try to use it inside a macro, I get, "WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options minoperator;&lt;BR /&gt;%macro velocity()/mindelimiter=',';&lt;/P&gt;&lt;P&gt;/*** Cycle through week one workday at a time ***/&lt;BR /&gt;%let first_date = %sysfunc(inputn(01JAN2019,date9.));&lt;BR /&gt;/*%sysfunc(intnx(month, %sysfunc(today()), -1,b)); */&lt;BR /&gt;%let end_date = %sysfunc(inputn(01APR2019,date9.));&lt;BR /&gt;%let i = 1;&lt;/P&gt;&lt;P&gt;%put first_date = &amp;amp;first_date.;&lt;/P&gt;&lt;P&gt;%do %while(&amp;amp;first_date. &amp;lt; &amp;amp;end_date.);&lt;/P&gt;&lt;P&gt;%put first_date = &amp;amp;first_date;&lt;BR /&gt;%let year1 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, -4), year.);&lt;BR /&gt;%let year2 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, 0), year.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there another option I need to use to get this to work?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 14:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584566#M166523</guid>
      <dc:creator>danteploy</dc:creator>
      <dc:date>2019-08-28T14:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584590#M166534</link>
      <description>&lt;P&gt;No, there's no option to get it to work.&amp;nbsp; In macro language, this is a string of 11 characters:&amp;nbsp; BankingDays&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not refer to a variable.&amp;nbsp; It's just a set of letters.&amp;nbsp; You would need to find its actual value (assuming there is just one and not a set of values), and transform it into a number representing the proper date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What advantage would you get from converting your code to macro language?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 14:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584590#M166534</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-28T14:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584610#M166540</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272389"&gt;@danteploy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the following code for generating date intervals.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options intervalds=(BankingDays=work.BankDayDS);&lt;BR /&gt;data BankDayDS (keep=BEGIN );&lt;BR /&gt;start = '01DEC2018'D;&lt;BR /&gt;stop = '01JAN2030'D;&lt;BR /&gt;nwkdays = INTCK('WEEKDAY',start,stop);&lt;BR /&gt;do i = 0 to nwkdays;&lt;BR /&gt;BEGIN = INTNX('WEEKDAY',start,i);&lt;BR /&gt;BEGIN_PERIOD = INTNX('WEEKDAY',start,i);&lt;BR /&gt;year = YEAR(BEGIN);&lt;BR /&gt;if BEGIN ne HOLIDAY('NEWYEAR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MLK',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USPRESIDENTS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('MEMORIAL',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('USINDEPENDENCE',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('LABOR',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('VETERANS',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('THANKSGIVING',year) and&lt;BR /&gt;BEGIN ne HOLIDAY('CHRISTMAS',year) then&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;format BEGIN DATE.;&lt;BR /&gt;format BEGIN_PERIOD MONYY.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works when I use it in intnx or intck in a data step.&amp;nbsp; But when I try to use it inside a macro, I get, "WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options minoperator;&lt;BR /&gt;%macro velocity()/mindelimiter=',';&lt;/P&gt;
&lt;P&gt;/*** Cycle through week one workday at a time ***/&lt;BR /&gt;%let first_date = %sysfunc(inputn(01JAN2019,date9.));&lt;BR /&gt;/*%sysfunc(intnx(month, %sysfunc(today()), -1,b)); */&lt;BR /&gt;%let end_date = %sysfunc(inputn(01APR2019,date9.));&lt;BR /&gt;%let i = 1;&lt;/P&gt;
&lt;P&gt;%put first_date = &amp;amp;first_date.;&lt;/P&gt;
&lt;P&gt;%do %while(&amp;amp;first_date. &amp;lt; &amp;amp;end_date.);&lt;/P&gt;
&lt;P&gt;%put first_date = &amp;amp;first_date;&lt;BR /&gt;%let year1 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, -4), year.);&lt;BR /&gt;%let year2 = %sysfunc(intnx(BankingDays, &amp;amp;first_date, 0), year.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another option I need to use to get this to work?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use a data step to create the macro variables? You don't show how you are using the macro variables so I can't tell if you actually need a completely macro solution.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   sd = '23JUN2020'd;
   nd = intnx('BankingDays',sd,4);
   call symputx('mvar',nd);
run;

%put mvar is: &amp;amp;mvar.;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 15:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584610#M166540</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-28T15:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584617#M166543</link>
      <description>Post your exact log please. &lt;BR /&gt;You're setting the option before you actually create the data set. Try reversing those settings and see what happens. But....at the same time not all functions are valid within SYSFUNC. For example you cannot use PUT or INPUT so it's possible that a user defined interval may not valid.</description>
      <pubDate>Wed, 28 Aug 2019 15:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584617#M166543</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-28T15:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584620#M166544</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. And if you need to avoid step boundaries (e.g. for a function-style macro), &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;DOSUBL&lt;/A&gt; comes to rescue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testf(first_date=);
%let rc=%sysfunc(%str(dosubl(data _null_;y=intnx('BankingDays', &amp;amp;first_date, -4);call symputx('year1', put(y,year.));run;)));
&amp;amp;year1
%mend testf;

%put %testf(first_date=21789);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result: 2019&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Custom intervals seem to be outside the scope of INTNX/INTCK when used via %SYSFUNC. Thanks for making us aware of this limitation.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 15:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584620#M166544</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-08-28T15:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584665#M166564</link>
      <description>&lt;P&gt;I tried changing the order of when I set the option, but get the same result.&amp;nbsp; Here's what the log says:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 17:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584665#M166564</guid>
      <dc:creator>danteploy</dc:creator>
      <dc:date>2019-08-28T17:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584668#M166565</link>
      <description>Thank you!</description>
      <pubDate>Wed, 28 Aug 2019 17:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-not-working-in-macro/m-p/584668#M166565</guid>
      <dc:creator>danteploy</dc:creator>
      <dc:date>2019-08-28T17:17:49Z</dc:date>
    </item>
  </channel>
</rss>

