<?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: Help Me find the error in the macro! in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525485#M4980</link>
    <description>&lt;P&gt;You need to use&amp;nbsp;enclose strings in double quotes if you want the macro processor to operate on the values. The single quotes prevent the macro processor from checking the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"01JAN&amp;amp;i"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is updated/simplified macro that does not need to worry about that since it eliminated the %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);

data aaa;
set HUF;

if (&amp;amp;year1 &amp;lt;= year(date) &amp;lt;= &amp;amp;year2) and
  put(date,date9.) in: ('01JAN' '15MAR' '08APR' '01MAY' '20AUG' '23OCT' '01NOV' '25DEC' '26DEC') 
then delete;

run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I suspect that to really do this right you would need to adjust the holiday schedule for each year to account for what day of the week the dates fall on.&amp;nbsp; In that case you might be better off using a dataset of holidays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With such a dataset your macro for generating the data step might look more like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);
%local dt_list ;
proc sql noprint;
  select date into :dt_list separated by ' '
  from holiday_schedule
  where year between &amp;amp;year1 and &amp;amp;year2
  ;
quit;

data aaa;
  set HUF;
  where date not in (&amp;amp;dt_list);
run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 Jan 2019 16:46:01 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-01-08T16:46:01Z</dc:date>
    <item>
      <title>Help Me find the error in the macro!</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525361#M4949</link>
      <description>&lt;P&gt;The following macro gives me errors like: Invalid date/time/datetime constant '01JAN&amp;amp;i.'d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);

data aaa;
set HUF;

%do i= &amp;amp;year1. %to &amp;amp;year2.;

if Date in ('01JAN&amp;amp;i.'d, '15MAR&amp;amp;i.'d, '08APR&amp;amp;i.'d, '01MAY&amp;amp;i.'d,
		'20AUG&amp;amp;i.'d, '23OCT&amp;amp;i.'d, '01NOV&amp;amp;i.'d, '25DEC&amp;amp;i.'d,
			'26DEC&amp;amp;i.'d) then delete;
%end;
run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&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;However, when I run the code without macro, it runs fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
set HUF;

if Date in ('01JAN2007'd, '15MAR2007'd, '08APR2007'd, '01MAY2007'd,
			'20AUG2007'd, '23OCT2007'd, '01NOV2007'd, '25DEC2007'd,
			'26DEC2007'd) then delete;
if Date in ('01JAN2008'd, '15MAR2008'd, '08APR2008'd, '01MAY2008'd,
			'20AUG2008'd, '23OCT2008'd, '01NOV2008'd, '25DEC2008'd,
			'26DEC2008'd) then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where's the error in the macro?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 09:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525361#M4949</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-08T09:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help Me find the error in the macro!</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525363#M4950</link>
      <description>&lt;P&gt;Single quotes prevent the resolution of macro triggers. Use double quotes instead.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 09:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525363#M4950</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-08T09:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help Me find the error in the macro!</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525364#M4951</link>
      <description>Macro list and statement genertion is not an ideal design. Rather have a look up table and update the look up table when needed</description>
      <pubDate>Tue, 08 Jan 2019 09:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525364#M4951</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-08T09:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help Me find the error in the macro!</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525466#M4977</link>
      <description>&lt;P&gt;It looks like the day and month are always the same, but the year changes. Are you trying to implement this for specific years?&amp;nbsp;&lt;BR /&gt;If so, you can avoid macro logic entirely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length ddmon $5.;

if year(date) in (2007, 2008, 2009) then do;

ddmon = put(date, date9.);

if ddmon in ('01JAN', '15MAR', '08APR' ...) then delete;

end;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/239423"&gt;@d6k5d3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The following macro gives me errors like: Invalid date/time/datetime constant '01JAN&amp;amp;i.'d.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);

data aaa;
set HUF;

%do i= &amp;amp;year1. %to &amp;amp;year2.;

if Date in ('01JAN&amp;amp;i.'d, '15MAR&amp;amp;i.'d, '08APR&amp;amp;i.'d, '01MAY&amp;amp;i.'d,
		'20AUG&amp;amp;i.'d, '23OCT&amp;amp;i.'d, '01NOV&amp;amp;i.'d, '25DEC&amp;amp;i.'d,
			'26DEC&amp;amp;i.'d) then delete;
%end;
run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&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;However, when I run the code without macro, it runs fine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
set HUF;

if Date in ('01JAN2007'd, '15MAR2007'd, '08APR2007'd, '01MAY2007'd,
			'20AUG2007'd, '23OCT2007'd, '01NOV2007'd, '25DEC2007'd,
			'26DEC2007'd) then delete;
if Date in ('01JAN2008'd, '15MAR2008'd, '08APR2008'd, '01MAY2008'd,
			'20AUG2008'd, '23OCT2008'd, '01NOV2008'd, '25DEC2008'd,
			'26DEC2008'd) then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where's the error in the macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 16:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525466#M4977</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-08T16:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help Me find the error in the macro!</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525485#M4980</link>
      <description>&lt;P&gt;You need to use&amp;nbsp;enclose strings in double quotes if you want the macro processor to operate on the values. The single quotes prevent the macro processor from checking the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"01JAN&amp;amp;i"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is updated/simplified macro that does not need to worry about that since it eliminated the %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);

data aaa;
set HUF;

if (&amp;amp;year1 &amp;lt;= year(date) &amp;lt;= &amp;amp;year2) and
  put(date,date9.) in: ('01JAN' '15MAR' '08APR' '01MAY' '20AUG' '23OCT' '01NOV' '25DEC' '26DEC') 
then delete;

run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I suspect that to really do this right you would need to adjust the holiday schedule for each year to account for what day of the week the dates fall on.&amp;nbsp; In that case you might be better off using a dataset of holidays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With such a dataset your macro for generating the data step might look more like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro domestic_holidays (year1, year2);
%local dt_list ;
proc sql noprint;
  select date into :dt_list separated by ' '
  from holiday_schedule
  where year between &amp;amp;year1 and &amp;amp;year2
  ;
quit;

data aaa;
  set HUF;
  where date not in (&amp;amp;dt_list);
run;

%mend domestic_holidays;

%domestic_holidays (2007, 2018);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jan 2019 16:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-Me-find-the-error-in-the-macro/m-p/525485#M4980</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-08T16:46:01Z</dc:date>
    </item>
  </channel>
</rss>

