BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello,

There is a Folder that contain multiple txt daily files with name structure  "Offers_YYYYMMDD"

(For example: Offers_20220701 is file for 01JULY2022 ).

The files are created almost everyday (non included non-business days and non included cases of fault running).

 

There is a data set called All_Days_tbl  that contain all dates between 01JAN2021  and Today.

In this data set there is a column called "path_to_Check"  that contain the File name that need to check if it exists or not.

 

The task is to create  a new column called "Indicator_File_Exists"  in  data set "All_Days_tbl " .

The column will get value 1 if the file exists and 0 if not .

Please note that I don't want to read the files (I just need to know which file exists and which not).

What is the way to do it please?

 

%let start_sas_date="01JAN2021"d;
%let Last_sas_date= "%sysfunc(today(),date9.)"d;
%put &start_sas_date;
%put &Last_sas_date;

data All_Days_tbl_(DROP=end_date);
date=&start_sas_date.;
end_date=&Last_sas_date.;
format date end_date date9.;
do while (date<=end_date);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;


Data All_Days_tbl;
SET All_Days_tbl_;
path_to_Check=CATS("/usr/local/SAS/offers_daily_Files/Loans.recomend.daily.",put(date,YYMMDDn8.));
Run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

No need for any macro variables and only your result data set is needed:

 

data example;
  length path_to_Check $ 200;
  do date="01JAN2021"d to today();
     path_to_Check=CATS('"',"/usr/local/SAS/offers_daily_files/Loans.recomend.daily.",put(date,YYMMDDn8.),'"');     
     ind = fileexist(path_to_Check);
     output;
  end;
run;

The fileexist returns 1 for found and 0 for not found so the IF /Then/ construct is a waste of clock cycles.

 

The iterated do will be easier to follow instead of the DO WHILE and avoids any possible infinite loop from a typo involving the incrementing of the dates.

For most purposes formatted date values just make macro coding difficult. The main usage would be in text that people read such as Title, Footnote text or file names.

View solution in original post

2 REPLIES 2
Ronein
Meteorite | Level 14

Okay,

I found the solution.

Here is the solution.

If there are other solutions I will be glad to see.


%let start_sas_date="01JAN2021"d;
%let Last_sas_date= "%sysfunc(today(),date9.)"d;
%put &start_sas_date;
%put &Last_sas_date;
data All_Days_tbl_(DROP=end_date);
date=&start_sas_date.;
end_date=&Last_sas_date.;
format date end_date date9.;
do while (date<=end_date);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;


Data All_Days_tbl;
SET All_Days_tbl_;
path_to_Check=CATS('"',"/usr/local/SAS/offers_daily_files/Loans.recomend.daily.",put(date,YYMMDDn8.),'"');
Run;
data wanted;
set All_Days_tbl;
IF fileexist(path_to_Check)  then Ind=1;else ind=0;
Run;
ballardw
Super User

No need for any macro variables and only your result data set is needed:

 

data example;
  length path_to_Check $ 200;
  do date="01JAN2021"d to today();
     path_to_Check=CATS('"',"/usr/local/SAS/offers_daily_files/Loans.recomend.daily.",put(date,YYMMDDn8.),'"');     
     ind = fileexist(path_to_Check);
     output;
  end;
run;

The fileexist returns 1 for found and 0 for not found so the IF /Then/ construct is a waste of clock cycles.

 

The iterated do will be easier to follow instead of the DO WHILE and avoids any possible infinite loop from a typo involving the incrementing of the dates.

For most purposes formatted date values just make macro coding difficult. The main usage would be in text that people read such as Title, Footnote text or file names.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 595 views
  • 2 likes
  • 2 in conversation