Desktop productivity for business analysts and programmers

Way to pick the latest file

Reply
Occasional Contributor
Posts: 10

Way to pick the latest file

Hi Everyone

I am using SAS Enterprise Guide in windows XP environment.

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.

Is there any way in SAS which I can use to do this?

Request your help.

Thanks
Shankar
Respected Advisor
Posts: 4,137

Re: Way to pick the latest file

Hi

You basically have to issue a command to the OS to get the information you need (i.e. creation date). So first thing you're doing is to open a command window (for Windows or UNIX - whatever your server environment is ) and get the command right. You then use either "filename ... pipe" or an "X" command from within SAS to send the "OS" command and retrieve the result for further processing. There are several examples in the SAS doc and in SAS notes of how to do this.

The one thing you should check first is if you're allowed to issue OS command from an EG session. Execute "Proc Options; run;" and then look in the log for "XCMD". If the value is "NOXCMD" (that's the installation default) then you've got a problem because EG won't allow you to issue OS commands. You then would have to talk to your SAS admin first.

HTH
Patrick
Occasional Contributor
Posts: 10

Re: Way to pick the latest file

Hi Patrick

Thanks for your reply.

However, as said I am not allowed to use any OS specific commands as they are disabled.

Any other way which I can use to do it apart from requesting SAS admin?

Please suggest.

Thanks
Shankar
Respected Advisor
Posts: 4,137

Re: Way to pick the latest file

Hi

You don't need to become a SAS admin - but your SAS admin would have to change NOXCMD to XCMD.

NOXCMD is a security feature. So there shouldn't be a way around it.

If you know the possible filenames then you could issue filename statements and then query the dictionary table. This would give you the information you're after.


filename tst1 'c:\temp\test.txt';
filename tst2 'c:\temp\test2.txt';

proc sql;
select *
from sashelp.vextfl
where fileref like 'TST%';
quit;


HTH
Patrick
PROC Star
Posts: 1,146

Re: Way to pick the latest file

Hi, Shankar

Here's a (slightly modified) piece of code that I use in EG on XP. It uses the SAS "External Files" functions to find the files in a directory. I only need the filename, but there's an "FINFO" function that you can probably use to get date information.

Tom

data work.dsns(keep=infref);
length infref $ 64;
rc=filename("htmldir","c:\Source");
htmld=dopen("htmldir");
dsncount=dnum(htmld);
do i = 1 to dsncount;
infref = dread(htmld,i);
end;
rc=dclose(htmld);
run;
Ask a Question
Discussion stats
  • 4 replies
  • 151 views
  • 0 likes
  • 3 in conversation