BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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.
11 REPLIES 11
darrylovia
Quartz | Level 8
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
Ksharp
Super User
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
SASPhile
Quartz | Level 8
I tried to run this changing the folder name,but dataset txt has zero records.
Ksharp
Super User
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
SASPhile
Quartz | Level 8
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
DBailey
Lapis Lazuli | Level 10
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
data_null__
Jade | Level 19
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.
Ksharp
Super User
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
NickR
Quartz | Level 8
I guess you need to add a back slash in between 'test' and '*'

filename txt pipe 'dir c:\temp\test\*.txt /od';
Ksharp
Super User
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
NickR
Quartz | Level 8
Ahh...you're right. I thought 'test' was a folder and we need to get the list of .txt files in that folder.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 11 replies
  • 3166 views
  • 0 likes
  • 6 in conversation