Dear All,
I need to find the pathname of a filename in sas. The input should be only the filename.
Is it possible in SAS? or anybody knows how this can be done in UNIX?
Thanks,
Chithra
Here's a step by step approach
data test;
value='C:\Windows\Test.txt';
file=scan(value,-1,"\");
endpos=find(value,strip(file));
path=substr(value,1,endpos-1);
run;
Try this.....
data WANT;
filename="c:\windows\text.txt";
path=substr(filename,1,find(filename,reverse(scan(reverse(filename),1,"\")))-1);
run;
Hope this helps.
Thanks.
But i have only the file name text.txt with me.
Don't know the path.
To find a file on a Unix server, type this at a Unix command line: find / -name text.txt
I wouldn't recommend doing this from SAS, assuming that you only want to do it once
yes..exactly.
Thanks. I use this command with pipe and it works fine.
Oh now i understand.
Now try this.
options noxwait;
FILENAME pathloc 'e:\test.txt';
data MYPATH;
x "dir e:\sample.txt /s /p > e:\test.txt";
infile pathloc;
input locator $100.;
if indexw(locator,'Directory of');
run;
#1 assign a fileref (just like a libname statement)
#2 Use x command and specify a directory and the file that will be searched, file is saved (same as fileref).
#3. Read the saved file.
#4 Look and retian the keywords "Directory of"
Hope this helps.
Thanks.
I tried this also. This helps.
Here's a step by step approach
data test;
value='C:\Windows\Test.txt';
file=scan(value,-1,"\");
endpos=find(value,strip(file));
path=substr(value,1,endpos-1);
run;
To find the path to a filename use:
%let myFilePath=%sysfunc(pathname(myFileName));
or for a library, use:
%let myLibraryPath=%sysfunc(pathname(myLibName));
See: https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245924.htm
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.
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.