BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

Hello everyone,

How to use SAS searchingenginer to search a file's physical location?

For example I have a file named "abc.txt", it locates at c:\myfile .I want to know what is the physical location of the file.

Given I only  know the file's name is "abc.txt" but I don't know where it is,...so how could I use searching enginer in SAS to get its location: "c:\temp"?

Thanks

Mike

15 REPLIES 15
art297
Opal | Level 21

Would using a pipe to run a dir command (assuming you are on windose) suffice?

Mike_Davis
Fluorite | Level 6

Hi Art,

Yes I am using wondows

Thanks

Mike

art297
Opal | Level 21

Mike,

Try something like:

filename indata pipe "dir \abc.txt /b /s";

data want;

  informat fil2read $255.;

  infile indata truncover;

  input fil2read &;

run;

Yanzheng
Calcite | Level 5

Great answer. It is working perfectly.

Mike_Davis
Fluorite | Level 6


Thank you Art,

the dir command works well but end with:  "file not found"

Mike

art297
Opal | Level 21

Mike,

Are you trying to find a file within your computer's c: drive, another drive on your computer, or on a network?

Yanzheng
Calcite | Level 5

Hi Mike:

Art' code work well. But you need a little bit change since everyone's computer config is different. if you file is sitting in d: driver, please add "x d:;". The code will be like:

x d:;

filename indata pipe "dir \abc.txt /b /s";

data want;

  informat fil2read $255.;

  infile indata truncover;

  input fil2read &;

run;

Tom
Super User Tom
Super User

Are you asking to know the full path to a file that you can already find?  You could use the FILENAME option on INFILE or FILE statement.

70   data _null_;

71    length filename $200;

72    infile 'myfile.txt' filename=filename;

73    putlog filename=;

74   run;

NOTE: The infile 'myfile.txt' is:

      Filename=C:\Documents and Settings\XXXXX\myfile.txt,

      RECFM=V,LRECL=256,File Size (bytes)=0,

      Last Modified=20Aug2012:15:05:10,

      Create Time=20Aug2012:15:05:10

filename=C:\Documents and Settings\XXXXX\myfile.txt

Mike_Davis
Fluorite | Level 6

Hi Tom,

The code has problem to run,

 

45 data _null;

46 length filename $200;

47 infile 'list.txt' filename=filename;

48 putlog filename=;

49 run;

ERROR: Physical file does not exist, H:\list.txt.

Thanks

Mike

ArtC
Rhodochrosite | Level 12

This error indicates to me that the file list.txt is not in the current directory (root of H:).  From the earlier posts it is still unclear to me that the OP knows the actual location of the file.

ScottBass
Rhodochrosite | Level 12

Hi Mike,

In a command window (start --> run --> cmd.exe), type "help dir" and carefully read the output.  Get your search working from Windows itself, then paste that code into Art's solution.

HTH,

Scott


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Reeza
Super User

What happens if two files with the same name are stored in different locations, ie a new version and backed up one?

It seems one of those things that you should know where to look rather than search.

Windows Search is really useful and you can search by extension, so if i see some one has created a dataset called hidden_data I can search for it using

hidden_data ext:sas and it will list SAS programs that have that dataset in the code.

art297
Opal | Level 21

Fareeza,

The code I suggested, which is basically using Window's search capabilities, will provide the full path to each file in the case of duplicate names.

Ksharp
Super User

Or chang it if your file is under D disk.

filename indata pipe " dir d:\x.txt /s/b ";

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 1862 views
  • 5 likes
  • 9 in conversation