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

Hello mentors,

 

I'm in a situation where I need to check the existence of a file in sas grid. The filename however has a date, which can be any date of the month, so there is no way to predict the full file name. For eg. in january, filename could be 'file_jan20_02jan20.sas7bdat', but in feb it could be 'file_feb20_08feb20.sas7bdat'. so there is absolutely no way to predict the right filename and look for it.

 

I usually use the following code to check the existence of the file, and I searched around but couldn't find a way to look for partial names such that if file: file_%SYSFUNC(TODAY(),monyy7.)_*.sas7bdat. Trying to do something along these lines using a wildcard.

data _null_;
rc=fileexist("/users/abc/filename.sas7bdat");                                                                                                                                   
if rc > 0 then call symput ('flag',"Y");
else call symput ('flag',"N");
run;
%put &=flag;

 

Appreciate your guidance so very much! 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Do you have already a libref to "/users/abc" ?

Suppose you don't have then:

libname mydata "/users/abc";

%let flag = "N";
data _null_;
   set sashelp.table;
        if libnmae = 'MYDATA' and
          lowcase(substr,memname,1,7) = 'file_jan'  /* or feb or ... */
         then do;
                 if memname = "<full data set name>" /* omit .sas7bdat */
                    then call symput('flag', "Y");
         end;
run;

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

Do you have already a libref to "/users/abc" ?

Suppose you don't have then:

libname mydata "/users/abc";

%let flag = "N";
data _null_;
   set sashelp.table;
        if libnmae = 'MYDATA' and
          lowcase(substr,memname,1,7) = 'file_jan'  /* or feb or ... */
         then do;
                 if memname = "<full data set name>" /* omit .sas7bdat */
                    then call symput('flag', "Y");
         end;
run;
AJ_Brien
Quartz | Level 8

That totally makes sense, thank you for the direction!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 735 views
  • 0 likes
  • 2 in conversation