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

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
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 7 replies
  • 1147 views
  • 7 likes
  • 5 in conversation