<?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 Using macro variable to refer to Date. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282316#M19368</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a program to read data files, filter and clean, and return a set of data falling within a specified date range. My program works fine and is relatively simple. However, when I add macro variables for the date range, the code will not run. I believe it is due to the fact that single quotes surround the datetime value. I have run into this problem before but within the proc import command where the path name must be surrounded by single quotes. In this instance I opted to use a "let" statement and input the path with the quotes around in rather than put the quotes into the code itself. However, this process is a bit more cumbersome because the date values can be long and I'd rather not have to type in such long datetime values in order to run my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the final piece of&amp;nbsp;code without the macro variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced1;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;= '27Jun2016:6:00'DT and WEBU_Datetime &amp;lt;= '4July2016:5:59'DT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(For my purposes, days begin at 6am and end at 5:59am the next day... for this reason the "time" portions do not need to change from one set of data to the next)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when I place the macro this is what it looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%&lt;/STRONG&gt;myprogram(begin, end)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;= '&amp;amp;begin:6:00'DT and WEBU_Datetime &amp;lt;= '&amp;amp;end:5:59'DT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this is the error I am receiving:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;24 data work.Time_Sourced;&lt;BR /&gt;25 set work.Time_Sourced;&lt;BR /&gt;26 where WEBU_Datetime &amp;gt;= '&amp;amp;begin:6:00'DT and WEBU_Datetime &amp;lt;= '&amp;amp;end:5:59'DT;&lt;BR /&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;begin:6:00'DT.&lt;BR /&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;end:5:59'DT.&lt;BR /&gt;ERROR: Syntax error while parsing WHERE clause.&lt;BR /&gt;27 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A way around this may be to use let statements and construct the macro variable from within the code. Such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%&lt;/STRONG&gt;myprogram(Date_Start,Date_End)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let Date1 = &amp;amp;Date_Start;&lt;/P&gt;&lt;P&gt;%let Date2 = &amp;amp;Date_End;&lt;/P&gt;&lt;P&gt;%let time = :6:00'DT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let begin= catt(',&amp;amp;Date_Start,time)&lt;/P&gt;&lt;P&gt;%let end = catt(',&amp;amp;Date_End,time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;=&amp;amp;begin and WEBU_Datetime &amp;lt;= &amp;amp;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that isn't working unsurprisingly. I believe the catt function is not operating the way I want it to. Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2016 23:00:34 GMT</pubDate>
    <dc:creator>SmcGarrett</dc:creator>
    <dc:date>2016-07-05T23:00:34Z</dc:date>
    <item>
      <title>Using macro variable to refer to Date.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282316#M19368</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a program to read data files, filter and clean, and return a set of data falling within a specified date range. My program works fine and is relatively simple. However, when I add macro variables for the date range, the code will not run. I believe it is due to the fact that single quotes surround the datetime value. I have run into this problem before but within the proc import command where the path name must be surrounded by single quotes. In this instance I opted to use a "let" statement and input the path with the quotes around in rather than put the quotes into the code itself. However, this process is a bit more cumbersome because the date values can be long and I'd rather not have to type in such long datetime values in order to run my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the final piece of&amp;nbsp;code without the macro variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced1;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;= '27Jun2016:6:00'DT and WEBU_Datetime &amp;lt;= '4July2016:5:59'DT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(For my purposes, days begin at 6am and end at 5:59am the next day... for this reason the "time" portions do not need to change from one set of data to the next)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when I place the macro this is what it looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%&lt;/STRONG&gt;myprogram(begin, end)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;= '&amp;amp;begin:6:00'DT and WEBU_Datetime &amp;lt;= '&amp;amp;end:5:59'DT;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this is the error I am receiving:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;24 data work.Time_Sourced;&lt;BR /&gt;25 set work.Time_Sourced;&lt;BR /&gt;26 where WEBU_Datetime &amp;gt;= '&amp;amp;begin:6:00'DT and WEBU_Datetime &amp;lt;= '&amp;amp;end:5:59'DT;&lt;BR /&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;begin:6:00'DT.&lt;BR /&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;end:5:59'DT.&lt;BR /&gt;ERROR: Syntax error while parsing WHERE clause.&lt;BR /&gt;27 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A way around this may be to use let statements and construct the macro variable from within the code. Such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%&lt;/STRONG&gt;myprogram(Date_Start,Date_End)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let Date1 = &amp;amp;Date_Start;&lt;/P&gt;&lt;P&gt;%let Date2 = &amp;amp;Date_End;&lt;/P&gt;&lt;P&gt;%let time = :6:00'DT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let begin= catt(',&amp;amp;Date_Start,time)&lt;/P&gt;&lt;P&gt;%let end = catt(',&amp;amp;Date_End,time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.Time_Sourced;&lt;BR /&gt;set work.Time_Sourced;&lt;BR /&gt;where WEBU_Datetime &amp;gt;=&amp;amp;begin and WEBU_Datetime &amp;lt;= &amp;amp;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that isn't working unsurprisingly. I believe the catt function is not operating the way I want it to. Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 23:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282316#M19368</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-07-05T23:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable to refer to Date.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282320#M19370</link>
      <description>&lt;P&gt;Macro triggers do not work inside of single quotes. Use double quotes instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin=27JUN2016 ;
%let end= 04JUL2016 ;

data Time_Sourced;
  set Time_Sourced;
  where "&amp;amp;begin:06:00"dt &amp;lt;= WEBU_Datetime &amp;lt;= "&amp;amp;end:05:59"dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jul 2016 23:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282320#M19370</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-05T23:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable to refer to Date.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282321#M19371</link>
      <description>&lt;P&gt;Wow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That was much more easy than I thought it would be.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2016 23:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-macro-variable-to-refer-to-Date/m-p/282321#M19371</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-07-05T23:56:05Z</dc:date>
    </item>
  </channel>
</rss>

