BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Barite | Level 11 woo
Barite | Level 11

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

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;

Jagadishkatam
Amethyst | Level 16

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;

Thanks,
Jag
art297
Opal | Level 21

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;

jakarman
Barite | Level 11

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"

---->-- ja karman --<-----
Reeza
Super User

I agree with Jaap, calculate the date you need and use that instead of searching the file names. 

woo
Barite | Level 11 woo
Barite | Level 11

Thanks All...i am going to try this out....Smiley Happy

woo
Barite | Level 11 woo
Barite | Level 11

i used "prxmatch" function is it worked fine - thanks all...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1872 views
  • 7 likes
  • 5 in conversation