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
Would using a pipe to run a dir command (assuming you are on windose) suffice?
Hi Art,
Yes I am using wondows
Thanks
Mike
Mike,
Try something like:
filename indata pipe "dir \abc.txt /b /s";
data want;
informat fil2read $255.;
infile indata truncover;
input fil2read &;
run;
Great answer. It is working perfectly.
Thank you Art,
the dir command works well but end with: "file not found"
Mike
Mike,
Are you trying to find a file within your computer's c: drive, another drive on your computer, or on a network?
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;
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
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
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.
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
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.
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.
Or chang it if your file is under D disk.
filename indata pipe " dir d:\x.txt /s/b ";
Ksharp
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.