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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.