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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1573 views
  • 0 likes
  • 2 in conversation