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!
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;
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;
That totally makes sense, thank you for the direction!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.