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
13 REPLIES 13
Tim_SAS
Barite | Level 11
Hi Shankar,

You might get better answers if you post your questions in the Enterprise Guide forum.

Good luck!
shankar_kumar
Calcite | Level 5
Thanks buddy.
art297
Opal | Level 21
Shankar,

I agree that those more familiar with EG might have a better response.

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:

http://www.hollandnumerics.co.uk/pdf/Using_EG_4.1(paper).pdf

And, with a pipe you can run a dos dir command and simply parse out what you need. E.g.,
[pre]
filename fnames pipe "dir c:\art\*.txt";
data have;
infile fnames;
informat date mmddyy10.;
informat time time8.;
informat fsize comma12.;
informat fname $32.;
input;
date = input(scan(_infile_,1," "), ?? mmddyy10.);
if not missing(date) then do;
time=input(scan(substr(_infile_,13),1," "), time8.);
fsize=input(scan(substr(_infile_,25),1," "), comma12.);
fname=input(scan(substr(_infile_,40),1," "), $32.);
output;
end;
run;

proc sort data=have;
by descending date descending time;
run;

data want;
set have (obs=1);
run;
[/pre]
HTH,
Art
---------
> 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
shankar_kumar
Calcite | Level 5
HI Art

Thanks for your input.

Unfortunately, the pipe is disabled by SAS admin. So, I am not able to use it.

Please suggest any other way.

Thanks
Shankar
SASKiwi
PROC Star
Are the files date-stamped in any way? If so something like this may help:

data _null_;
rc=filename('mydir','c:\mydir');
did=dopen('mydir');
numopts=doptnum(did);
memcount=dnum(did);
if (memcount gt 0) then
do i = 1 to memcount;
filename=dread(did,i);
fid = mopen(did, filename,'i',0,'d');
optname=foptname(fid,2);
recfm=finfo(fid,optname);
optname=foptname(fid,3);
lrecl=finfo(fid,optname);
rc=fclose(fid);
put filename = recfm= lrecl=;
end;
rc=dclose(did);
run;

Unfortunately you can't get the file dates this way, but you can get the names.
Pritish
Quartz | Level 8
Shankar,

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
SASKiwi
PROC Star
Pritish,

Do you have SAS 9.2 and did you check out the FINFO documentation link above?
Pritish
Quartz | Level 8
@SASKiwi:

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.

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?
darrylovia
Quartz | Level 8
you can also check DINFO to get all the items in a directory
Pritish
Quartz | Level 8
Darrylovia:

DINFO will give me only the count of the items in a directory. Is that correct?
SASKiwi
PROC Star
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.
SASKiwi
PROC Star
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:
[pre]
data _null_;
rc=filename('mydir','C:\mydir');
did=dopen('mydir');
numopts=doptnum(did);
memcount=dnum(did);
if (memcount gt 0) then do i = 1 to memcount;
filename=dread(did,i);
fid = mopen(did, filename,'i',0,'d');
optname=foptname(fid,2);
recfm=finfo(fid,optname);
optname=foptname(fid,3);
lrecl=finfo(fid,optname);
optname=foptname(fid,5);
last_updated=finfo(fid,optname);
rc=fclose(fid);
put filename = recfm= lrecl= last_updated = ;
end;
rc=dclose(did);
run;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 6712 views
  • 0 likes
  • 6 in conversation