<?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: Way to pick the latest file in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67354#M19262</link>
    <description>you can also check DINFO to get all the items in a directory</description>
    <pubDate>Thu, 02 Jun 2011 16:57:49 GMT</pubDate>
    <dc:creator>darrylovia</dc:creator>
    <dc:date>2011-06-02T16:57:49Z</dc:date>
    <item>
      <title>Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67344#M19252</link>
      <description>Hi Everyone&lt;BR /&gt;
&lt;BR /&gt;
I am using SAS Enterprise Guide in windows XP environment.&lt;BR /&gt;
&lt;BR /&gt;
As part of my automation work, I need to pick the latest .txt file from a list of different files in a folder and then do some operations on that.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way in SAS which I can use to do this?&lt;BR /&gt;
&lt;BR /&gt;
Request your help.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Shankar</description>
      <pubDate>Thu, 19 May 2011 12:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67344#M19252</guid>
      <dc:creator>shankar_kumar</dc:creator>
      <dc:date>2011-05-19T12:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67345#M19253</link>
      <description>Hi Shankar,&lt;BR /&gt;
&lt;BR /&gt;
You might get better answers if you post your questions in the &lt;A href="http://support.sas.com/forums/forum.jspa?forumID=10" target="_blank"&gt;Enterprise Guide forum&lt;/A&gt;.&lt;BR /&gt;
&lt;BR /&gt;
Good luck!</description>
      <pubDate>Thu, 19 May 2011 13:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67345#M19253</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2011-05-19T13:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67346#M19254</link>
      <description>Shankar,&lt;BR /&gt;
&lt;BR /&gt;
I agree that those more familiar with EG might have a better response.&lt;BR /&gt;
&lt;BR /&gt;
One brute force method would be to use a unnamed pipe.  The following article mentions what you would have to do to use a pipe in EG:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.hollandnumerics.co.uk/pdf/Using_EG_4.1(paper).pdf" target="_blank"&gt;http://www.hollandnumerics.co.uk/pdf/Using_EG_4.1(paper).pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
And, with a pipe you can run a dos dir command and simply parse out what you need.  E.g.,&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename fnames pipe "dir c:\art\*.txt";&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile fnames;&lt;BR /&gt;
  informat date mmddyy10.;&lt;BR /&gt;
  informat time time8.;&lt;BR /&gt;
  informat fsize comma12.;&lt;BR /&gt;
  informat fname $32.;&lt;BR /&gt;
  input;&lt;BR /&gt;
  date = input(scan(_infile_,1," "), ?? mmddyy10.);&lt;BR /&gt;
  if not missing(date) then do;&lt;BR /&gt;
    time=input(scan(substr(_infile_,13),1," "), time8.);&lt;BR /&gt;
    fsize=input(scan(substr(_infile_,25),1," "), comma12.);&lt;BR /&gt;
    fname=input(scan(substr(_infile_,40),1," "), $32.);&lt;BR /&gt;
	output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
  by descending date descending time;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have (obs=1);&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art&lt;BR /&gt;
---------&lt;BR /&gt;
&amp;gt; Hi Everyone&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I am using SAS Enterprise Guide in windows XP&lt;BR /&gt;
&amp;gt; environment.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; As part of my automation work, I need to pick the&lt;BR /&gt;
&amp;gt; latest .txt file from a list of different files in a&lt;BR /&gt;
&amp;gt; folder and then do some operations on that.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Is there any way in SAS which I can use to do this?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Request your help.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks&lt;BR /&gt;
&amp;gt; Shankar</description>
      <pubDate>Thu, 19 May 2011 13:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67346#M19254</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-05-19T13:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67347#M19255</link>
      <description>Thanks buddy.</description>
      <pubDate>Thu, 19 May 2011 13:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67347#M19255</guid>
      <dc:creator>shankar_kumar</dc:creator>
      <dc:date>2011-05-19T13:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67348#M19256</link>
      <description>HI Art&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your input.&lt;BR /&gt;
&lt;BR /&gt;
Unfortunately, the pipe is disabled by SAS admin. So, I am not able to use it.&lt;BR /&gt;
&lt;BR /&gt;
Please suggest any other way.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Shankar</description>
      <pubDate>Thu, 19 May 2011 17:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67348#M19256</guid>
      <dc:creator>shankar_kumar</dc:creator>
      <dc:date>2011-05-19T17:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67349#M19257</link>
      <description>Are the files date-stamped in any way? If so something like this may help:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  rc=filename('mydir','c:\mydir');&lt;BR /&gt;
  did=dopen('mydir');&lt;BR /&gt;
  numopts=doptnum(did);&lt;BR /&gt;
  memcount=dnum(did);&lt;BR /&gt;
  if (memcount gt 0) then&lt;BR /&gt;
   do i = 1 to memcount;&lt;BR /&gt;
      filename=dread(did,i);&lt;BR /&gt;
      fid = mopen(did, filename,'i',0,'d');&lt;BR /&gt;
      optname=foptname(fid,2);&lt;BR /&gt;
	  recfm=finfo(fid,optname);&lt;BR /&gt;
      optname=foptname(fid,3);&lt;BR /&gt;
	  lrecl=finfo(fid,optname);&lt;BR /&gt;
      rc=fclose(fid);&lt;BR /&gt;
	  put filename = recfm= lrecl=;&lt;BR /&gt;
   end;&lt;BR /&gt;
  rc=dclose(did);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Unfortunately you can't get the file dates this way, but you can get the names.</description>
      <pubDate>Fri, 20 May 2011 01:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67349#M19257</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2011-05-20T01:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67350#M19258</link>
      <description>Actually if you have SAS 9.2 you can do it. Check this out:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-func-finfo.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-func-finfo.htm&lt;/A&gt;</description>
      <pubDate>Fri, 20 May 2011 03:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67350#M19258</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2011-05-20T03:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67351#M19259</link>
      <description>Shankar, &lt;BR /&gt;
&lt;BR /&gt;
I am looking out some solution for the same problem. Did you get any solutions on how it can be done?

Message was edited by: Pritish</description>
      <pubDate>Wed, 01 Jun 2011 18:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67351#M19259</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2011-06-01T18:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67352#M19260</link>
      <description>Pritish,&lt;BR /&gt;
&lt;BR /&gt;
Do you have SAS 9.2 and did you check out the FINFO documentation link above?</description>
      <pubDate>Wed, 01 Jun 2011 20:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67352#M19260</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2011-06-01T20:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67353#M19261</link>
      <description>@SASKiwi: &lt;BR /&gt;
&lt;BR /&gt;
I am using SAS EG 4.2. Even I checked the link that you had posted and it seems like for getting the data it is looking for / require a file name. &lt;BR /&gt;
&lt;BR /&gt;
My scenaio is like: The file get's dropped into the folder everyday but the file name  might change everytime it get's loaded. So I am looking for something which is not dependent on the file name. Any idea?</description>
      <pubDate>Thu, 02 Jun 2011 14:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67353#M19261</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2011-06-02T14:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67354#M19262</link>
      <description>you can also check DINFO to get all the items in a directory</description>
      <pubDate>Thu, 02 Jun 2011 16:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67354#M19262</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-06-02T16:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67355#M19263</link>
      <description>Darrylovia: &lt;BR /&gt;
&lt;BR /&gt;
DINFO will give me only the count of the items in a directory. Is that correct?</description>
      <pubDate>Thu, 02 Jun 2011 20:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67355#M19263</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2011-06-02T20:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67356#M19264</link>
      <description>If you look at the program I posted above, all you have to do is put your own directory in the FILENAME function in the second line and it will find all files in that directory. The program does need to be changed to pick up the last updated date using FINFO, but the documentation link explains how to do it.</description>
      <pubDate>Thu, 02 Jun 2011 20:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67356#M19264</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2011-06-02T20:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Way to pick the latest file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67357#M19265</link>
      <description>Just to make it easier I checked this solution out on SAS 9.2. Just change the C:\mydir to the directory you want to check:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  rc=filename('mydir','C:\mydir');&lt;BR /&gt;
  did=dopen('mydir');&lt;BR /&gt;
  numopts=doptnum(did);&lt;BR /&gt;
  memcount=dnum(did);&lt;BR /&gt;
  if (memcount gt 0) then do i = 1 to memcount;&lt;BR /&gt;
    filename=dread(did,i);&lt;BR /&gt;
    fid = mopen(did, filename,'i',0,'d');&lt;BR /&gt;
    optname=foptname(fid,2);&lt;BR /&gt;
    recfm=finfo(fid,optname);&lt;BR /&gt;
    optname=foptname(fid,3);&lt;BR /&gt;
    lrecl=finfo(fid,optname);&lt;BR /&gt;
    optname=foptname(fid,5);&lt;BR /&gt;
    last_updated=finfo(fid,optname);&lt;BR /&gt;
    rc=fclose(fid);&lt;BR /&gt;
    put filename = recfm= lrecl= last_updated = ;&lt;BR /&gt;
  end;&lt;BR /&gt;
  rc=dclose(did);&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 03 Jun 2011 08:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Way-to-pick-the-latest-file/m-p/67357#M19265</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2011-06-03T08:07:50Z</dc:date>
    </item>
  </channel>
</rss>

