BookmarkSubscribeRSS Feed
gnesshunkin
Calcite | Level 5

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!

7 REPLIES 7
Reeza
Super User

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.

Shmuel
Garnet | Level 18

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;     
   
alexal
SAS Employee

On UNIX you can do something like this:

 

find /path/to/folder/ -regextype posix-egrep -regex ".*\.(sas)$" 2> /dev/null | xargs grep -i 'keyword'
DrSAS
Fluorite | Level 6

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.

Sajid01
Meteorite | Level 14

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 4641 views
  • 5 likes
  • 7 in conversation