Reputation: 37
I have SAS code in which there is following line of code is included
% include "/sas/dev/compare.sas";
it is at location on server /sas/cpm/dev/code
So, at present what I am doing manually go to above path and open each .sas code(in a Folder, you can say there are 4 codes location at /sas/cpm/dev/code) and check whether %include "/sas/dev/compare.sas" line of code is present or not
Can anyone help me without checking/open manually .sas code how to check whether %include "/sas/dev/compare.sas"; is exist or not
Can anyone , please help me how to write in sas, We can pass each code through macro right
Thanks
Upvotes: 0
Views: 386
Reputation: 1804
You can do this by:
% include "/sas/dev/compare.sas";
Code:
%let extension=sas;
%let FolderPath=\\sas\SASDATA\momo\;
%macro check_file_path(f=);
DATA _null_;
infile "&f" dsd ;
length string $200.;
input string $;
if string=&check. then put "&f. " "includes @ line " _N_= ;
run;
%mend;
Data List_files;
rc=FILENAME('FMyRep',"&FolderPath");
did=DOPEN('FMyRep');
memcnt=DNUM(did);
*count number of members - including subfolders;
DO i=1 TO memcnt;
*for each member, test extension and store filename;
filevar=LOWCASE(DREAD(did,i));
file_path=cats("&FolderPath.",filevar);
IF LOWCASE(SCAN(filevar,-1,".")) EQ LOWCASE("&extension") THEN
OUTPUT;
END;
rc=DCLOSE(did);
rc=FILENAME('FMyRep');
KEEP filevar file_path;
RUN;
data _null_;
set List_files;
call execute('%check_file_path(f='||file_path||')');
put file_path=;
run;
Output:
file_path=\\sas\SASDATA\momo\file1.sas
file_path=\\sas\SASDATA\momo\file2.sas
file_path=\\sas\SASDATA\momo\file3.sas
file_path=\\sas\SASDATA\momo\file4.sas
Log: file4.sas is the only one that doesn't have this % include "/sas/dev/compare.sas";
\\sas\SASDATA\momo\file1.sas includes @ line _N_=1
\\sas\SASDATA\momo\file2.sas includes @ line _N_=1
\\sas\SASDATA\momo\file4.sas includes @ line _N_=1
Upvotes: 1
Reputation: 3315
you can do it by using fileexist function
%let myfile = "/sas/dev/compare.sas";
%macro filecheck;
%if %sysfunc(fileexist(&myfile))
%then % include "/sas/dev/compare.sas";
%else %put The external file &myfile does not exist.;
%mend;
%filecheck;
Upvotes: 0