BookmarkSubscribeRSS Feed
shankar_kumar
Calcite | Level 5
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
4 REPLIES 4
Patrick
Opal | Level 21
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
shankar_kumar
Calcite | Level 5
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
Patrick
Opal | Level 21
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
TomKari
Onyx | Level 15
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2291 views
  • 0 likes
  • 3 in conversation