<?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: Reference the last directory created by a libname statement with a macro date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151955#M29928</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it's feasible, you could always link the two programs.&amp;nbsp; For example, the last statement in Program 1 could be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include program2.sas;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I know there are posters here who can solve this.&amp;nbsp; There definitely are ways to say, "Create a list of all subfolder names, and read that into a DATA step."&amp;nbsp; Then have the DATA step find the largest value.&amp;nbsp; Presumably the largest value is the right one, since all your sufolders would belong to the same month.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Aug 2014 17:46:01 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2014-08-06T17:46:01Z</dc:date>
    <item>
      <title>Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151953#M29926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello! I’m still pretty new to SAS. Please bear with me while I ask my question. I created a directory with my libname statement that creates a daily folder named after the date it was created. If I wanted to reference those tables in the last folder created in another program how would I do that? Currently I run the programs on separate days and I’m having to manually change the libname statement to reference the last date ran. I would like to automate it if at all possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UDIR= My user directory&lt;/P&gt;&lt;P&gt;Rundate = 06AUG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Program 1 that creates the directory:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; options&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;dlcreatedir&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LIBNAME&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; X &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;"&amp;amp;UDIR\SAS TABLES\201408\&amp;amp;RUNDATE"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Program 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white;"&gt;What I would like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LIBNAME&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; X &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;"&amp;amp;UDIR\SAS TABLES\201408\&amp;amp;RUNDATE"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; What I currently have to do:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LIBNAME&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; X &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;"&amp;amp;UDIR\SAS TABLES\201408\05AUG"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 17:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151953#M29926</guid>
      <dc:creator>mcrum1</dc:creator>
      <dc:date>2014-08-06T17:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151954#M29927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote my rundate out to a txt file then read the text file into the second program.&amp;nbsp; I made the value in the text file a macro variable in the second program.&amp;nbsp; I am certain that SAS experts have more novel solutions.&lt;/P&gt;&lt;P&gt;(not tested)&lt;/P&gt;&lt;P&gt;/* at end of program 1 */&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file 'my file to hold the date value.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "&amp;amp;rundate.";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* at beginning of program 2 */&lt;/P&gt;&lt;P&gt;filename datex 'my file to hold the date value.txt";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datex.....&lt;/P&gt;&lt;P&gt;&amp;nbsp; input.........&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symput........&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 17:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151954#M29927</guid>
      <dc:creator>jwillis</dc:creator>
      <dc:date>2014-08-06T17:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151955#M29928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it's feasible, you could always link the two programs.&amp;nbsp; For example, the last statement in Program 1 could be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include program2.sas;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I know there are posters here who can solve this.&amp;nbsp; There definitely are ways to say, "Create a list of all subfolder names, and read that into a DATA step."&amp;nbsp; Then have the DATA step find the largest value.&amp;nbsp; Presumably the largest value is the right one, since all your sufolders would belong to the same month.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 17:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151955#M29928</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-08-06T17:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151956#M29929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does this help? Given your input the macro variable lastdate gets the previous day and month. This will cross months and years.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt; %let Rundate = 06AUG;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt; %let Lastdate= &lt;/SPAN&gt;&lt;SPAN style="color: #ff0080; font-size: 10pt; font-family: SAS Monospace;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;(inputn(&amp;amp;rundate.2014,date9.));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt; %let lastdate= &lt;/SPAN&gt;&lt;SPAN style="color: #ff0080; font-size: 10pt; font-family: SAS Monospace;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;(putn(&amp;amp;lastdate-1,date5.));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt; %put &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;&amp;amp;lastdate;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 19:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151956#M29929</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-08-06T19:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151957#M29930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) If they both run on the same day then program 2 can use the same logic to set RUNDATE as program 1.&lt;/P&gt;&lt;P&gt;2) If program 2 always runs the day after Program 1 then you can calculate yesterday's date from today's date:&amp;nbsp; &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; prevrun=&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("&amp;amp;sysdate9"d -1,date5.));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;LIBNAME&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; X &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"&amp;amp;UDIR\SAS TABLES\201408\&amp;amp;prevrun"&lt;/SPAN&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;3) you could store the last run date and path used into a table and pull it out again in program 2.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Program1:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/SPAN&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 style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;insert&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; libref.lastrun (datetime,pathname)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;values&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: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(datetime()),&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"%sysfunc(pathname(x))"&lt;/SPAN&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 style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&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;Program 2:&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;noprint&lt;/SPAN&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 style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; quote(trim(pathname)) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; :pathname &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; libref.lastrun&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime=max(datetime)&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 style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&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 style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;libname&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; x &amp;amp;pathname ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) You could read the directories and figure out which is the last one from the name.&amp;nbsp; But for this to work you really should convert from using 05AUG to something more complete.&amp;nbsp; I like to use dates in YYYYMMDD format for date stamps in file names because then they sort naturally.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 21:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151957#M29930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-06T21:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151958#M29931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will use OS command ( X statement ) to get these the newest table name and use them in the new code .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 13:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151958#M29931</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-07T13:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151959#M29932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also keep a log file in your root directory:&lt;/P&gt;&lt;P&gt;LIBNAME&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; X &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;"&amp;amp;UDIR\SAS TABLES";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;data x.log;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attrib last_run_date format=date9. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; folder_location format=$2000.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_run_date='06JUL2014'd;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; folder_loction="\06JUL";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;Then each time you run your program, at the end have a brief step to insert the new value:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into x.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set last_run_date=today(),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; folder_location="\"||substr(put(today(),date9.),1,5);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;If you want the latest dated one then:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select folder_location&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into&amp;nbsp;&amp;nbsp; :floc&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having max(last_run_date);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;libname last "%sysfunc(pathname(x))\&amp;amp;floc.";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 13:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151959#M29932</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-08-07T13:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151960#M29933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting challenge&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sometimes automating our SAS environment takes a bit longer than expected. One example might be the time it takes for the DOPEN and FOPEN functions to deliver the latest file or directory name in a path when compared with checking existence of a file and a second.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an approach using a few small macros&lt;/P&gt;&lt;P&gt;1 NEW_DAY_LIB&lt;/P&gt;&lt;P&gt;create a library based on today&lt;/P&gt;&lt;P&gt;2 PRIOR_LIB&lt;/P&gt;&lt;P&gt;if prior_L global symbol doesn't exists, create it as today &lt;/P&gt;&lt;P&gt;Try assigning a library for &amp;amp;prior_L&lt;/P&gt;&lt;P&gt;if it fails (&amp;amp;syslibrc=0) subtract 1 from prior_L and try assignment again&lt;/P&gt;&lt;P&gt;When assignment succeeds (&amp;amp;syslibrc=1) exit the macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Interesting challenge in PRIOR_LIB to code for handling a month-end with&amp;nbsp; a new parent folder when today is 1st September&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Supporting NEW_LIB is the function dcreate(). It can be wrapped within %sysfunc(). It enables sas users of enterprise guide sharing a server to create folders witbout needing X statements or PIPE&amp;nbsp; filenames.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might be interesting and appear simpler to make PRIOR_LIB&amp;nbsp; recursive, but the depth limit would probably be breached if the user came back from a 10 day holiday &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;interesting challenge&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Aug 2014 07:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151960#M29933</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-08-10T07:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reference the last directory created by a libname statement with a macro date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151961#M29934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is some question more generic as just SAS. It is about running business applications infrastructure supporting different stages of DTAP (Develop Test User-Acceptance Production) and using a business-reference date. &lt;BR /&gt;You can see those settings as some generic set to be set up at startup of the business-processing for all kind of processes.&lt;/P&gt;&lt;P&gt;For production business-systems often the today() setting is used. While in testing environments you must have a fixed setting to be able to do regression testing. with fixed test-datasets during a verification. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within that kind of processed a loop of recurrent daily processes can exist with a at that moment becoming point of date.&lt;/P&gt;&lt;P&gt;I believe this is what you are doing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Putting is in one program and do a %include of that in every other program belonging will solve the redundancy.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Setting program. "bu_001_refdate.sas"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp; %let&amp;nbsp; UDIR= My user directory\;&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp; %let&amp;nbsp; Uxlib=&amp;amp;UDIR.SAS TABLES\201408\;&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp; %let Rundate = 06AUG;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;options&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;dlcreatedir&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;. LIBNAME&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; X &lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New';"&gt;"&amp;amp;Uxlib.&amp;amp;RUNDATE"&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;All of your other programs starting with:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;&amp;nbsp; %include "&amp;amp;ugenset.bu_001_refdate.sas" &lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;This is a start as you see to eliminate all kind of physical namings from the coding.&lt;BR /&gt;By that the code will be able to run on all type of machinetypes with little modifications&lt;BR /&gt;&lt;BR /&gt;There must be a last step/process being run that validates all processing has ended successfully and a next iteration / new date / can be started. That is a nice trigger for a sas-job for creating/writing out the sas-source: bu_001_refdate.sas &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;The ugenset macrovariabel is something to set in a startup/autoexec as there must be a location where your code is to be found. &lt;BR /&gt;The %include is similar of calling a sub-program as used in many other program languages for modular constructs.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Aug 2014 08:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reference-the-last-directory-created-by-a-libname-statement-with/m-p/151961#M29934</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-10T08:50:38Z</dc:date>
    </item>
  </channel>
</rss>

