BookmarkSubscribeRSS Feed
Codexgo
Fluorite | Level 6

Hi Folks,

 

How can i scan list of keywords on multiple SAS programs files. By SAS or Shell Script or any other way to achieve it?

 

Thanks

6 REPLIES 6
Codexgo
Fluorite | Level 6

Hi Kurt,

 

I am trying below mentioned code in SAS but its not working. Also if i want to search more than one keyword - e.g. along with libname, infile, import, how to do it ?

 

Thanks.

 

filename find 'grep "libname" Path*.sas';

data test;
infile find truncover;
input find_words $100.;
run;

Kurt_Bremser
Super User

You missed a keyword:

filename find pipe 'grep "libname" Path*.sas 2>&1';
data test;
infile find truncover;
input find_words $100.;
run;

I also added a redirection of stderr to stdout, so that all possible responses will be caught in the data step.

Codexgo
Fluorite | Level 6

 

 

HI Kurt,

 

I am getting this error while executing the code: 

 

 

ERROR: Insufficient authorization to access PIPE.
ERROR: Error in the FILENAME statement.
74 data test;
75 infile find truncover;
76 input find_words $100.;
77 run;
 
ERROR: No logical assign for filename FIND 
FreelanceReinh
Jade | Level 19

Hi @Codexgo,

 

A "cousin" of grep in the Windows world is findstr (to be used on the command line, cmd.exe):

findstr "keyword1 keyword2 ..." *.sas

would find all lines in .sas files in the current folder containing one or more keywords from the list. Various options could be specified to modify the search, e.g., /s to extend it to all subfolders.

 

Similar functionality ("Find in files") is offered by some text editors (and other utility software) and, of course, you could write a SAS program for this purpose. I mostly use findstr.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1888 views
  • 2 likes
  • 3 in conversation