Hello please help me on how can i use latest available date from all similar list of files.
lets say i have 50 text files with same name uploaded on different date in directory "d:\woo" and lets say latest date file is 9/11/2014 and i want to use that file - how can i get that file in use...
/*i am using this code to read all files at once*/
/*but then how can i use latest file*/
%let ext=txt;
%let dir=f:\woo\;
data files_list;
length fname1 $200;
infile "dir &dir.*.&ext /tw " pipe truncover lrecl=3000 ;
input fname1 $200.;
run;
Thanks -
Sounds more like a question on how to use the DOS DIR command.
/tw - will tell it to use the WRITE date
/o-d - will tell it to sort with most recent first.
/b - will tell it to only list the names.
%let ext=txt;
%let dir=f:\woo\;
data _null_;
infile "dir /tw /o-d /b &dir.*.&ext" pipe truncover obs=1 ;
input fname $256. ;
call symputx('fname',fname);
run;
data want ;
infile "&dir.&fname" .... ;
....
Since you can't have multiple files with the same name in a directory, your description of the problem is missing something.
How are the files named?
oppsss...my bad...files are like this;
filename date_modified
test_file_123567_8756453 09/11/2014
test_file_365435_8755454 08/11/2014
.
.
.
test_file_025489_4587001 07/10/2014
What does your file_list dataset look like?
test_file_123567_8756453
test_file_365435_8755454
.
.
.
test_file_025489_4587001
Run the dir command in a windows cmd line to see what the output looks like then modify your input statement to read the correct variables.
sort by date and take the first.
I'm also 99% sure this question has been asked on the forum before so searching may be easier.
Here is an example:
%let ext=txt;
%let dir=c:\path\;
data files_list;
length fname1 $200;
length date 8;
length time $5;
length size $10;
length fname $128;
infile "dir &dir.*.&ext /tw " pipe truncover lrecl=3000 ;
input fname1 $200.;
if index(fname1, "&ext");
date = input(scan(fname1,1,' '),DDMMYY10.); format date YYMMDD10.;
time = scan(fname1,2,' ');
size = scan(fname1,3,' ');
fname = scan(fname1,4,' ');
run;
proc sort data=files_list;
by date time;
run;
This is what it looks like in the sorted dataset:
infile "dir &dir.*.&ext /tw " pipe truncover lrecl=3000 ;
In this infile statement, why we've used /tw?
//Tw is the windows command to include last modified time in the output.
Instead of piping and analyzing that output you could use the dinfo function. This sample gives a dir listing.
SAS(R) 9.4 Companion for Windows, Third Edition (dinfo proc)
Note the " error in the source example second tempdir, it is easy to correct
This code also runs unchanged under Unix only the returned list is different. The advantage is no failures in analyzing that returned output.
Sounds more like a question on how to use the DOS DIR command.
/tw - will tell it to use the WRITE date
/o-d - will tell it to sort with most recent first.
/b - will tell it to only list the names.
%let ext=txt;
%let dir=f:\woo\;
data _null_;
infile "dir /tw /o-d /b &dir.*.&ext" pipe truncover obs=1 ;
input fname $256. ;
call symputx('fname',fname);
run;
data want ;
infile "&dir.&fname" .... ;
....
could be avoided using dinfo
thanks all for your quick response...i would go with PIPE option though...Thank you...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.