<?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: Export Output &amp;sysdate -1 filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181062#M265160</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I worked it out...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT date = %SYSFUNC(PUTN(%sysevalf(%SYSFUNC(TODAY())-1),DATE9.));&lt;/P&gt;&lt;P&gt;proc export dbms=csv&lt;/P&gt;&lt;P&gt;data=WORK.data&lt;/P&gt;&lt;P&gt;outfile="S:\D\D\DData_&amp;amp;date..csv"&lt;/P&gt;&lt;P&gt;replace&lt;/P&gt;&lt;P&gt;label;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Apr 2014 04:51:45 GMT</pubDate>
    <dc:creator>breelloyd</dc:creator>
    <dc:date>2014-04-16T04:51:45Z</dc:date>
    <item>
      <title>Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181059#M265157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to export a file and bring in yesterdays date into the file name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traditionally, we name files using the extract date- but we've been asked to do something differently this time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc export dbms=csv&lt;/P&gt;&lt;P&gt;data=WORK.data&lt;/P&gt;&lt;P&gt;outfile="S:\D\D\ &amp;amp;sysdate..csv"&lt;/P&gt;&lt;P&gt;replace&lt;/P&gt;&lt;P&gt;label;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I dynamically do this? ie &amp;amp;sysdate-1 for example.&lt;/P&gt;&lt;P&gt;so if I ran the file today, the file name would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;15Apr14.csv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 03:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181059#M265157</guid>
      <dc:creator>breelloyd</dc:creator>
      <dc:date>2014-04-16T03:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181060#M265158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT&amp;nbsp; %SYSFUNC(PUTN(%sysevalf(%SYSFUNC(TODAY())-1),DATE9.));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 04:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181060#M265158</guid>
      <dc:creator>SKK</dc:creator>
      <dc:date>2014-04-16T04:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181061#M265159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How would that look in my program?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc export dbms=csv&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data=WORK.data&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%PUT&amp;nbsp; %SYSFUNC(PUTN(%sysevalf(%SYSFUNC(TODAY())-1),DATE9.));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;outfile="S:\D\D\ &amp;amp;sysdate..csv"&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;replace&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;label;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;??&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I'm pretty new to coding in SAS &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 04:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181061#M265159</guid>
      <dc:creator>breelloyd</dc:creator>
      <dc:date>2014-04-16T04:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181062#M265160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I worked it out...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT date = %SYSFUNC(PUTN(%sysevalf(%SYSFUNC(TODAY())-1),DATE9.));&lt;/P&gt;&lt;P&gt;proc export dbms=csv&lt;/P&gt;&lt;P&gt;data=WORK.data&lt;/P&gt;&lt;P&gt;outfile="S:\D\D\DData_&amp;amp;date..csv"&lt;/P&gt;&lt;P&gt;replace&lt;/P&gt;&lt;P&gt;label;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 04:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181062#M265160</guid>
      <dc:creator>breelloyd</dc:creator>
      <dc:date>2014-04-16T04:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181063#M265161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your program you are referencing the value of a macro variable by using&amp;nbsp; &amp;amp;SYSDATE.&lt;/P&gt;&lt;P&gt;You could use also reference a macro function call. In particular the %SYSFUNC() macro function that lets you reference anyone of many SAS functions in macro code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;export&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;dbms&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=WORK.data&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;outfile&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"S:\D\D\%sysfunc(putn("&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;amp;sysdate9&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"d-1,date.)).csv"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;replace&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; label&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a couple of things to watch out for here.&lt;/P&gt;&lt;P&gt;1) I changed from using SYSDATE (which is formatted with a two digit year) to SYSDATE9 (which is the same value formatted with a four digit year).&lt;/P&gt;&lt;P&gt;2) I used the date literal syntax "ddMMMyyyy"d to convert the string that is in the SYSDATE9 macro variable back into a valid SAS date value and then subtracted one to get "yesterday".&lt;/P&gt;&lt;P&gt;3) I used the DATE format so that the value will look like what you used before (15APR14) but I strongly recommend using a flavor of YYMMDD format when putting date strings into filenames. These values will sort naturally into date order when sorted as character strings. If you use ddMMMyy format then the order in your directory of files will look almost random.&lt;/P&gt;&lt;P&gt;4) Note that SYSDATE is the date that SAS started and might not be today's date.&amp;nbsp; If the session starts right before midnight or has been running a long time. If this is being run by users from interactive sessions then you are better off using the DATE(),&amp;nbsp; or its alias&amp;nbsp; TODAY(), function instead.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;5) You could create a macro variable with the formatted date of choice and then the coding is a little clearer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; yesterday=&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(putn(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(date())-1,yymmdd10)); &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;export&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;dbms&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=WORK.data&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;outfile&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"S:\D\D\&amp;amp;yesterday..csv"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;replace&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; label&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 05:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181063#M265161</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-04-16T05:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export Output &amp;sysdate -1 filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181064#M265162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep you are right, you can even supply your own values also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 05:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-Output-sysdate-1-filename/m-p/181064#M265162</guid>
      <dc:creator>SKK</dc:creator>
      <dc:date>2014-04-16T05:08:51Z</dc:date>
    </item>
  </channel>
</rss>

