Help using Base SAS procedures

Searching SAS files (including key words) in Windows 7

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

Searching SAS files (including key words) in Windows 7

I want to search my network drive for SAS programs that have a key word I'm looking for.  When I was running XP, i could do a search such as *.*sas and it would prompt me for any word I wanted to include in the contents of the file.  If I typed "PROC IMPORT" (without the double quotes) I would get all SAS programs that had PROC IMPORT in the program.  I have no such luck in Windows 7.


Accepted Solutions
Solution
‎05-24-2017 01:37 PM
Trusted Advisor
Posts: 1,301

Re: Searching SAS files (including key words) in Windows 7

[ Edited ]

In command prompt:

 

Search the H drive for all files with extension of sas for string obs=max

 

for /r H: %i in (*.sas) do @findstr /i /m "obs=max" "%i"

 

In sas your could execute this in a filename pipe and then collect all the relevant filenames inside a data step.

 

filename search pipe 'for /r H: %i in (*.sas) do @findstr /i /m "obs=max" "%i"';
 
data search_results;
  infile search length=_len;
  input @1 filepath $varying512. _len;
run;

View solution in original post


All Replies
PROC Star
Posts: 7,487

Searching SAS files (including key words) in Windows 7

Actually, the same problem existed in XP, but you apparently had SAS identified as a valid search extension.

I'm still on XP and had to look up how to correct the matter.  For anyone interested, you can find the solutions (I chose the one at the bottom of the page that didn't require playing with the registry:

http://www.dslreports.com/faq/9500

And, while I haven't had much experience with Windows 7, I think that you may be able to find the solution at:

http://helpdeskgeek.com/windows-7/windows-7-file-search-indexing-options/

Let the forum know if that corrected the situation.

Super Contributor
Posts: 358

Searching SAS files (including key words) in Windows 7

Hi:

By default, the Windows 7 search will not examine the contents of the file and the indexing that Art is referring to only works on the file name.

Here is a better link on how to search file contents with Windows 7:

http://lifehacker.com/5666506/set-windows-7-search-to-always-index-file-contents

Super Contributor
Posts: 279

Searching SAS files (including key words) in Windows 7

I'm trying the step in the first post but in the 2nd post I can't find "enabling universal content search" in the Search tab.

PROC Star
Posts: 7,487

Searching SAS files (including key words) in Windows 7

I would think that my translate to the "always search file names and contents (this might take several minutes)" option on the search options menu

Solution
‎05-24-2017 01:37 PM
Trusted Advisor
Posts: 1,301

Re: Searching SAS files (including key words) in Windows 7

[ Edited ]

In command prompt:

 

Search the H drive for all files with extension of sas for string obs=max

 

for /r H: %i in (*.sas) do @findstr /i /m "obs=max" "%i"

 

In sas your could execute this in a filename pipe and then collect all the relevant filenames inside a data step.

 

filename search pipe 'for /r H: %i in (*.sas) do @findstr /i /m "obs=max" "%i"';
 
data search_results;
  infile search length=_len;
  input @1 filepath $varying512. _len;
run;
Super Contributor
Posts: 279

Re: Searching SAS files (including key words) in Windows 7

This is excellent!  When I searched the H drive it worked great.  I'm not sure what to do with the part that starts with "filename search pipe......"

Trusted Advisor
Posts: 1,301

Searching SAS files (including key words) in Windows 7

It is only necessary if you wanted to perform the search through sas and have the results returned in a data set.  Also there is a typo in my code len=_len should read length=_len.

Super Contributor
Posts: 279

Searching SAS files (including key words) in Windows 7

Holy s**t!!  This is incredible.  Once I corrected your typo, off she flew.  I can play Traffic Rush the rest of the day.

PROC Star
Posts: 7,487

Searching SAS files (including key words) in Windows 7

Gregg,

I have a complaint to raise!  How could FriedEgg provide such an incredible finding, but you credit yourself for having provided the answer?  Am I missing something here?

Super Contributor
Posts: 279

Searching SAS files (including key words) in Windows 7

Apparently I don't know all the intricasies of this site but I take no credit for the solution.  Fried Egg is the top dog on this topic.

PROC Star
Posts: 7,487

Searching SAS files (including key words) in Windows 7

Gregg,

Understood.  It is a fairly new model for the site and there aren't a lot of initricasies.  Simply bring up his post and click on the "correct" button or, if that is no longer available, the "helpful" button.  Except for the handful of
SAS employees that are here, the majority of respondents are just other users like you and me.  The formal recognition they get is through obtaining approval ratings from their peers.

SAS Employee
Posts: 3

Searching SAS files (including key words) in Windows 7

I ran into a similar problem and my solution was to build a SAS macro that would search within sas programs to find the string.

Here is a link to the macro that my colleague and I wrote.

http://www.torsas.ca/attachments/File/09162011/macro-that-hunts.txt

You should be able to put in the drive/directory you want to search, the file type (in this case .sas) and the string you want to look for.  Keep the proc printto statements as we found the macro ran a lot faster.

Hope that helps and is what you are looking for.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 3451 views
  • 0 likes
  • 5 in conversation