Hello all. I am working on a project where I need to identify all SAS programs that are using a list of variables anywhere in the program. I would like to be able to search a directory at a time and have SAS output the program names that use those variables. I have been using the below code, however it is only identifying if the variables are being used in joins etc and doesn't flag the report if it is just in the select statement. Any help would be greatly appreciated! %macro srch_dir(dir=\\WFSISF20\Reports\Service Files\Code ,words= first_var second_var third_var); %let words=%upcase(&words); %if &sysscp=%str(WIN) %then %do; filename piped pipe "dir /b ""&dir"" "; %end; %else %if &sysscp=%str(SUN 4) %then %do; filename piped pipe "ls ""&dir"" "; %end; data work.progs; length progname $200; infile piped; input progname; run; filename piped clear; data _null_; retain n 0; call symput('n',n); set work.progs (obs=0) nobs=n; stop; run; data work.words (keep=w word); length word $300 words $300; retain words "&words"; w = 1; word = scan(words,w,' '); do while (word ne ''); output; w + 1; word = scan(words,w,' '); end; call symput('w',w-1); run; %if &n > 0 %then %do; %do i=1 %to &n; data _null_; retain n &i; set work.progs point=n; call symput('progname',progname); stop; run; %if &sysscp=%str(WIN) %then %do; %let prog=&dir\&progname; %end; %else %if &sysscp=%str(SUN 4) %then %do; %let prog=&dir/&progname; %end; data work.elines(keep=program word textline n); file = "&prog"; length word $300 program $200; retain program "&prog" file "&prog"; infile dummy filevar=file truncover end=eof; input textline $200.; textline = upcase(textline); n+1; %do j = 1 %to &w; word = scan("&words",&j,' '); if indexw(upcase(textline),word)>0 then output; %end; run; proc append base=work.lines new=work.elines; run; %end; data _null_; retain numobs 0; call symput('numobs',numobs); set work.lines (obs=0) nobs=numobs; stop; run; %if &numobs > 0 %then %do; title Programs in &dir with occurrences of the word(s) &words; options ls=116 ps=85; proc report data=work.lines nowd split='#'; column program word n textline; break after program / page; break after word / skip; define program / order "Program Name" width=20 flow; define word / order "Word Found"; define n / order "Line Number"; define textline / "Line" width=40 flow; run; title; proc datasets lib=work nolist; delete lines elines words progs; run; quit; %end; %else %do; data _null_; put "WARNING: No files in &dir contain the word(s) &words"; run; %end; %end; %else %do; data _null_; put "WARNING: No files found in directory &dir"; run; %end; %mend;
... View more