Skip to content

Instantly share code, notes, and snippets.

@hdary85
Last active November 21, 2023 14:39
Show Gist options
  • Save hdary85/3b57828ea3fb7d981c6926b118bc3ca2 to your computer and use it in GitHub Desktop.
Save hdary85/3b57828ea3fb7d981c6926b118bc3ca2 to your computer and use it in GitHub Desktop.
%let folder_path = "your_folder_path"; /* Specify the path to your folder */
%let table_name = "xyz"; /* Specify the table name to search for */
/* Create a fileref for the directory */
filename dirlist "&folder_path" ;
/* Get a list of SAS program files in the folder */
data sas_files;
length file_name $256.;
infile dirlist truncover;
/* Read each line from the directory listing */
do while (1);
input line $256.;
/* Check if the file has a .sas extension */
if index(upcase(line), ".SAS") > 0 then do;
file_name = line;
output;
end;
end;
/* Close the directory fileref */
file dirlist;
drop line;
run;
/* Loop through each SAS program file to check if it references the table 'xyz' */
data check_table_reference;
set sas_files;
/* Read the content of the SAS program file */
infile "&folder_path.\&file_name" lrecl=32767 truncover dlmstr='09'x;
length line $32767;
do while (not eof);
input;
line = _infile_;
/* Check if the table 'xyz' is referenced in the SAS program */
if index(upcase(line), upcase("&table_name")) > 0 then do;
put "&file_name references table &table_name.";
/* You can add more actions or store the information as needed */
end;
end;
drop line;
run;
%let folder_path
/* Get a list of SAS program files in the folder */
filename filelist pipe "dir /B &folder_path\*.sas";
data sas_files;
length file_name $256.;
infile filelist truncover;
input file_name $256.;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment