- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
We are upgrading systems and tables/variables are being deprecated which will potentally cause my code to fail. Does anyone have a way to search all the SAS code in my folder for combinations of certain keywords?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Windows SEARCH will do that or a Unix line command. IMO those are faster and more appropriate for this type of request.
That being said, this question was asked on here a few weeks ago so if you search on here there's at least one full solution to searching all files in a folder for specific words.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If your codes are stored on UNIX, a find with -exec grep will do the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have posted next code few months ago.
You need supply your argumnet as macro variables in first 3 lines of the code.
I use it in linux but believe it can be used in windows too. Try it:
%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&root.sas_help/*.&suffix");
data results;
length fname _filepath $200;
infile finp filename = _filepath eov=_eov truncover;
input a_line $200.;
fname = _filepath;
if _eov=1 then do;
_n=0;
_eov=0;
end;
_n+1;
if find(a_line,"&search_string",'i')
then output;
keep _n a_line fname;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
On UNIX you can do something like this:
find /path/to/folder/ -regextype posix-egrep -regex ".*\.(sas)$" 2> /dev/null | xargs grep -i 'keyword'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Actually, my version looks a little simpler:
find /path_to_folder -name \*.sas -exec grep -i keyword {} \; -print > keyword_prog.lst
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Set up Microsoft File Explorer find keywords in a SEARCH of .sas files
When you use Windows File Explorer to SEARCH for keyword they don't show up. The search may not include files of with certain extensions! In fact, quite a few file extensions/types will be omitted. Microsoft created this situation deliberately, to avoid having you find "irrelevant" files and SAS was left out from this list. Updating the Windows Registry will rectify this and allow Windows to search the file types you need.
The Search relies on an internal filter to look at a limited group of files Those file extensions that don't have a defined HKEY_CLASSES_ROOT filter won't be searched. If you find that certain file extensions don't appear in the search results, you can try assigning the plain-text filter to those types.
To have Windows File Explorer search files of a certain file extension in this case .SAS:
1. launch Regedit from the Start menu's Run dialog.
2. navigate to the key HKEY_CLASSES_ROOT\.??? (where .??? is the extension you want searched - sas).
a. If you don't find a subkey named PersistentHandler, create one.
3. double-click on the value "(Default)" for that subkey to set its value to {5e941d80-bf96-11cd-b579-08002b30bfeb}
• Administrator rights are needed to perform this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A simple approach on windows would be to use power shell. The syntax is given below
Select-String -Path c:\folder1\*.sas -pattern string1.string2