<?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 use date throughout code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484474#M125786</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;May i request your opinion on this style&lt;/P&gt;
&lt;P&gt;%let start_date = 01jan2018 ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_ ; &lt;BR /&gt; new_date = "&amp;amp;start_date"d + 10 ;&lt;BR /&gt; put new_date=yymmdd10. ; &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coz it appears the macro data is anyway hardcoded?&lt;/P&gt;</description>
    <pubDate>Mon, 06 Aug 2018 18:22:07 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-08-06T18:22:07Z</dc:date>
    <item>
      <title>How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484468#M125782</link>
      <description>&lt;P&gt;How do I declare a specific date that I want to use throughout my code. I have three date fields and only want to type the date once. Here is wht I use in sql and want to translate it in sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Declare&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; @Start_Date &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;DAte&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; @Start_Date &lt;/FONT&gt;&lt;FONT color="#808080" face="Consolas" size="2"&gt;=&lt;/FONT&gt; &lt;FONT color="#ff0000" face="Consolas" size="2"&gt;'2018-01-01'&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484468#M125782</guid>
      <dc:creator>asherer</dc:creator>
      <dc:date>2018-08-06T18:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484469#M125783</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to use throughout my code ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It sounds like you want a macro variable that can be used in any data step or PROC or with other macro commands. Is that correct?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = %sysfunc(mdy(1,1,2018));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Then any place you use &amp;amp;date, the proper date value will be inserted and used by your code. Example, assuming there is a variable named DATE in MYDB:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select * from mydb where date &amp;gt; &amp;amp;date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484469#M125783</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-06T18:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484470#M125784</link>
      <description>&lt;P&gt;do you mean you want to know the syntax of a sas date constant&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;date='01jan2018'd;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484470#M125784</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-06T18:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484473#M125785</link>
      <description>&lt;P&gt;At the top of the program, code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = %sysfunc (inputn (2018-01-01, yymmdd10)) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then, anywhere in the program downstream, refer to it as &amp;amp;start_date. No quotes! For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                  
  new_date = &amp;amp;start_date + 10 ;
  put new_date=yymmdd10. ;     
run ;                          &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You'll see in the SAS log:&lt;/P&gt;&lt;PRE&gt;new_date=2018-01-11&lt;/PRE&gt;&lt;P&gt;Remember, in SAS date is not a character string but an integer equal to the number of days since the beginning of 1960 (or before that point, in which case it's negative). The date of 1960-01-01 has the value of 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484473#M125785</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-06T18:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484474#M125786</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;May i request your opinion on this style&lt;/P&gt;
&lt;P&gt;%let start_date = 01jan2018 ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_ ; &lt;BR /&gt; new_date = "&amp;amp;start_date"d + 10 ;&lt;BR /&gt; put new_date=yymmdd10. ; &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coz it appears the macro data is anyway hardcoded?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484474#M125786</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-06T18:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484475#M125787</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;May i request your opinion on this style&lt;/P&gt;
&lt;P&gt;%let start_date = 01jan2018 ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _null_ ; &lt;BR /&gt; new_date = "&amp;amp;start_date"d + 10 ;&lt;BR /&gt; put new_date=yymmdd10. ; &lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coz it appears the macro data is anyway hardcoded?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's more effort (and also more likelihood of mis-typing) if quotes are required. And probably just a hair slower as each time SAS has to convert 01jan2018 to an internal date value.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484475#M125787</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-06T18:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484476#M125788</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Point taken and learned something new. I didn't know the constant would under perform. Interesting insight!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus I was of wrong assumption, a macro processor is a touch slower than data step compiler especially when it came to interfaces i.e using conventional data step functions. The pause caused by the macro processor while tokenisation and then interface activity and then back to tokenisation before all processed tokens are moved to compiler for execution&amp;nbsp; is what took me by surprise.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484476#M125788</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-06T18:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484481#M125789</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no problem with this style, but if I used it, I'd rather code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = '01jan2018'd ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and used it in the subsequent code just as &amp;amp;start_date, so that I wouldn't have to quote and add the literal suffix D every time. It also leaves less interpretive work to the compiler. The reason I offered:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = %sysfunc (inputn (2018-01-01, yymmdd10)) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is merely because the OP seems to prefer this input format since this is what was used in the original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484481#M125789</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-06T18:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484482#M125790</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;I know why you answered as pointed to the needs of OP. But you know me by now, I just jumped into learn something extra. I am cheeky. Can't help it&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 18:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484482#M125790</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-06T18:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484536#M125800</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no problem with this style, but if I used it, I'd rather code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = '01jan2018'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and used it in the subsequent code just as &amp;amp;start_date, so that I wouldn't have to quote and add the literal suffix D every time. It also leaves less interpretive work to the compiler. The reason I offered:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = %sysfunc (inputn (2018-01-01, yymmdd10)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is merely because the OP seems to prefer this input format since this is what was used in the original post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And quite often I use the macro variable an just the date9 format&amp;nbsp; 01JAN2018 because I then use the same macro variable in Title or Footnotes as well as the filter statements such as startdate ge "&amp;amp;date."d and/or document names. But what works for very simple&amp;nbsp;code, many of my ad hoc requests are somewhat repetitive except for dates so include the specific requested dates in usually a title statement, may not be appropriate for much manipulation.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 21:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484536#M125800</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-06T21:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use date throughout code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484542#M125803</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That which fits one's purpose best is what needs to be done.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 21:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-date-throughout-code/m-p/484542#M125803</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-06T21:20:29Z</dc:date>
    </item>
  </channel>
</rss>

