DATA Step, Macro, Functions and more

Dymanically determine last modified date

Reply
Super Contributor
Posts: 673

Dymanically determine last modified date

how to dymanically determine last modified date for a set of files and then move them to a separate folder?
for instance if c:\temp has the following files
test1.txt
test2.txt
text3.txt

and test2.txt is the last modified file.it needs to be moved to c:\results.
Frequent Contributor
Posts: 139

Re: Dymanically determine last modified date

If you are using windows you can use the FINFO function which gives you the modiied date (this is for 9.2 only)

http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-func-finfo.htm

D
Super User
Posts: 10,041

Re: Dymanically determine last modified date

And Operate System Command will be more power.
[pre]
filename txt pipe 'dir c:\temp\test*.txt /od';
data txt;
infile txt expandtabs truncover dlm=' ';
input dt anydtdtm20. size $ fname $20.;
format dt datetime20.;
if not missing(dt) then output;
run;
data _null_;
set txt end=last;
if last then call system('move c:\temp\'||fname||' c:\results\'||fname);
run;
[pre]


Ksharp
Super Contributor
Posts: 673

Re: Dymanically determine last modified date

I tried to run this changing the folder name,but dataset txt has zero records.
Super User
Posts: 10,041

Re: Dymanically determine last modified date

I am not sure what wrong it happened.
But I test it successfully in my OS. Maybe Due to the encodeing of OS(mine is Chinese Win).
Can you post the result of command " dir ..... /od" .
I will fix it.

Ksharp
Super Contributor
Posts: 673

Re: Dymanically determine last modified date

KSharp,
the folder has three text files:
thats why I used wild character *
The error is:
Stderr output:
The system cannot find the path specified.

filename txt pipe 'dir C:\Documents and Settings\Desktop\Excel SAS\test\*.txt /od';
data txt;
infile txt expandtabs truncover dlm=' ';
input dt anydtdtm20. size $ fname $20.;
format dt datetime20.;
if not missing(dt) then output;
run;
data _null_;
set txt end=last;
if last then call system('move C:\Documents and Settings\Desktop\Excel SAS\test\'||fname|| ' C:\Documents and Settings\Desktop\Excel SAS\test\results\'||fname);
run;



53 filename txt pipe 'dir C:\Documents and Settings\Desktop\Excel SAS\test\*.txt /od';
54 data txt;
55 infile txt expandtabs truncover dlm=' ';
56 input dt anydtdtm20. size $ fname $20.;
57 format dt datetime20.;
58 if not missing(dt) then output;
59 run;

NOTE: The infile TXT is:
Unnamed Pipe Access Device,
PROCESS=dir C:\Documents and Settings\Desktop\Excel SAS\test\*.txt /od,
RECFM=V,LRECL=256

Stderr output:
The system cannot find the path specified.
NOTE: 0 records were read from the infile TXT.
NOTE: The data set WORK.TXT has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.70 seconds
cpu time 0.01 seconds


60 data _null_;
61 set txt end=last;
62 if last then call system('move C:\Documents and Settings\Desktop\Excel
62 ! SAS\test\'||fname|| ' C:\Documents and Settings\Desktop\Excel
62 ! SAS\test\results\'||fname);
63 run;

NOTE: There were 0 observations read from the data set WORK.TXT.
NOTE: DATA statement used (Total process time):
real time 0.12 seconds
cpu time 0.01 seconds
Super Contributor
Posts: 578

Re: Dymanically determine last modified date

If I remember my windows environments correctly, there is always a user between the "documents and settings" and the "desktop". Like this

C:\Documents and Settings\username\Desktop

There is also a public

C:\Documents and Settings\public\Desktop
Respected Advisor
Posts: 3,799

Re: Dymanically determine last modified date

Don't you need to quote a path with spaces.
[pre]
filename txt pipe 'dir "C:\Documents and Settings\Desktop\Excel SAS\test\*.txt" /od';
[/pre]

Test the windows command in a dos box if it don't work there it won't PIPE.
Super User
Posts: 10,041

Re: Dymanically determine last modified date

I test it.Found the reason.
It is because the name of directory(Excel SAS) contains white blank.
So the command dir is failed.
If you can, change the name to ExcelSAS without blank.

Ksharp
Frequent Contributor
Posts: 81

Re: Dymanically determine last modified date

I guess you need to add a back slash in between 'test' and '*'

filename txt pipe 'dir c:\temp\test\*.txt /od';
Super User
Posts: 10,041

Re: Dymanically determine last modified date

That is not right. test*.txt is identified test1.txt testab.txt .... etc.
* is wildchar which stands for any txt filename start with test.

Ksharp
Frequent Contributor
Posts: 81

Re: Dymanically determine last modified date

Ahh...you're right. I thought 'test' was a folder and we need to get the list of .txt files in that folder.
Ask a Question
Discussion stats
  • 11 replies
  • 1356 views
  • 0 likes
  • 6 in conversation