Hi Friends please help me to pull today's date from below group of files
I have too many group file like below in one directory and i want to pull only today's file
Dir: d:\woo\test_dir
files under this dir are like;
customer_data_2015.04.06_test.txt
customer_data_2015.04.07_test.txt
customer_data_2015.04.08_test.txt
customer_data_2015.04.09_test.txt
customer_data_2015.04.10_test.txt
product_2015.04.08_test.txt
product_2015.04.09_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.04_test.txt
plant_detail_description_2015.04.05_test.txt
plant_detail_description_2015.04.06_test.txt
plant_detail_description_2015.04.07_test.txt
plant_detail_description_2015.04.08_test.txt
plant_detail_description_2015.04.09_test.txt
plant_detail_description_2015.04.10_test.txt
so for example i just need latest files (lets say today's file);
customer_data_2015.04.10_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.10_test.txt
Ok! If perl functions can be used that way:
data have;
informat directory $80.;
input directory;
cards;
customer_data_2015.04.06_test.txt
customer_data_2015.04.07_test.txt
customer_data_2015.04.08_test.txt
customer_data_2015.04.09_test.txt
customer_data_2015.04.10_test.txt
product_2015.04.08_test.txt
product_2015.04.09_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.04_test.txt
plant_detail_description_2015.04.05_test.txt
plant_detail_description_2015.04.06_test.txt
plant_detail_description_2015.04.07_test.txt
plant_detail_description_2015.04.08_test.txt
plant_detail_description_2015.04.09_test.txt
plant_detail_description_2015.04.10_test.txt
;
data want;
set have;
if input(substr(directory,
prxmatch('/\d\d\d\d\.\d\d\.\d\d/',directory),10),yymmdd10.)
eq today();
run;
My perl skills are at an extremely novice level, but I think that the following example achieves what you want:
data have;
informat directory $80.;
input directory;
cards;
customer_data_2015.04.06_test.txt
customer_data_2015.04.07_test.txt
customer_data_2015.04.08_test.txt
customer_data_2015.04.09_test.txt
customer_data_2015.04.10_test.txt
product_2015.04.08_test.txt
product_2015.04.09_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.04_test.txt
plant_detail_description_2015.04.05_test.txt
plant_detail_description_2015.04.06_test.txt
plant_detail_description_2015.04.07_test.txt
plant_detail_description_2015.04.08_test.txt
plant_detail_description_2015.04.09_test.txt
plant_detail_description_2015.04.10_test.txt
;
data want;
set have;
format y date9.;
re=prxparse('/\d\d\d\d\.\d\d\.\d\d/');
x=prxmatch(re,directory);
if x gt 0 then do;
if input(substr(directory,x,10),yymmdd10.) eq today();
end;
run;
data have;
input txt$100.;
date=input(substr(txt,prxmatch('/\d{4}\.\d{2}\.\d{2}/',txt),10),yymmdd10.);
cards;
customer_data_2015.04.06_test.txt
customer_data_2015.04.07_test.txt
customer_data_2015.04.08_test.txt
customer_data_2015.04.09_test.txt
customer_data_2015.04.10_test.txt
product_2015.04.08_test.txt
product_2015.04.09_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.04_test.txt
plant_detail_description_2015.04.05_test.txt
plant_detail_description_2015.04.06_test.txt
plant_detail_description_2015.04.07_test.txt
plant_detail_description_2015.04.08_test.txt
plant_detail_description_2015.04.09_test.txt
plant_detail_description_2015.04.10_test.txt
;
%let td=%sysfunc(today());
%put &td;
proc sort data=have out=want;
by txt;
where date=&td;
run;
Ok! If perl functions can be used that way:
data have;
informat directory $80.;
input directory;
cards;
customer_data_2015.04.06_test.txt
customer_data_2015.04.07_test.txt
customer_data_2015.04.08_test.txt
customer_data_2015.04.09_test.txt
customer_data_2015.04.10_test.txt
product_2015.04.08_test.txt
product_2015.04.09_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.04_test.txt
plant_detail_description_2015.04.05_test.txt
plant_detail_description_2015.04.06_test.txt
plant_detail_description_2015.04.07_test.txt
plant_detail_description_2015.04.08_test.txt
plant_detail_description_2015.04.09_test.txt
plant_detail_description_2015.04.10_test.txt
;
data want;
set have;
if input(substr(directory,
prxmatch('/\d\d\d\d\.\d\d\.\d\d/',directory),10),yymmdd10.)
eq today();
run;
A pitty yuo are not using Unix the filenames pattern/wildcards could solve that more elegant: SAS(R) 9.4 Companion for UNIX Environments, Fourth Edition
Windows is only allowing the * but that one could be sufficient having "today-s date" as a macro var available. Based on the naming convention of your files not the system dates.
customer_data_2015.04.10_test.txt
product_2015.04.10_test.txt
plant_detail_description_2015.04.10_test.txt
Will become:
%let today=%sysfunc(putn("10Apr15"d, yymmddp10.) ) ; %put &today ; /* when needed the date as constant */
%let today=%sysfunc(putn("&sysdate"d, yymmddp10.) ) ; %put &today ; /* when needed as moving system date */
/* other methods as next date as result of previous are to be coded */
For use in the infile:
"customer_data_&today._test.txt"
"product_&today._test.txt"
"plant_detail_description_&today._test.txt"
An all files of today (use the filename option of the infile statement:
"*_&today._test.txt"
I agree with Jaap, calculate the date you need and use that instead of searching the file names.
Thanks All...i am going to try this out....
i used "prxmatch" function is it worked fine - thanks all...
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.