BookmarkSubscribeRSS Feed
fanfanpao
Fluorite | Level 6
suppose i have folder new and a subfolder new1 within it. i have 3 txt files in folder new. my program is in new1. i want to get the file name of 3 text files. the code is filename aa pipe "ls ../*.txt". but the log show no such files. but when run the ls command in the terminal, it show all 3 file name. why?
7 REPLIES 7
Kurt_Bremser
Super User

Please post the whole code you used with the filename pipe.

And keep in mind that the commandline has a different current working directory than the SAS workspace server.

yabwon
Onyx | Level 15
Are the SAS "./" and commandline's "./" the same?
Try "pwd; ls ../*.txt:?
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



fanfanpao
Fluorite | Level 6
pls note that i run the code in the batch mode. i assume ./ is the same path of the program, and ../ is the path of up level folder of the program. i will take a try of pwd command later. thank you both.
ballardw
Super User

I never use relative paths and always start from a drive or root mount point just in case something like a batch system for some reason has a different execution default locations(different config files can do that).

Kurt_Bremser
Super User

@fanfanpao wrote:
pls note that i run the code in the batch mode.

Please note that (as an example) sasbatch.sh in Lev1/SASApp/Batchserver calls Lev1/SASApp/ calls appservercontext_env.sh, which explicitly sets the working directory to Lev1/SASApp.

Similar things can (and will) happen in other SAS batch scripts.

Bottom line: NEVER use a relative path unless you have already explicitly set the required current working directory yourself. See Maxim 31.

ChrisNZ
Tourmaline | Level 20

The execution location is not necessarily that of the program file.

See your config file(s).

yabwon
Onyx | Level 15

Hi @fanfanpao ,

 

one another thing which came into my mind, if you know the "wanted" starting location in advance, would be use of DLGCDIR() function, to change current working directory, like in the example:

 

%put *%sysfunc(pathname(WORK))*;
%put *%sysfunc(DLGCDIR(%sysfunc(pathname(WORK))))*;

filename test "."; /*fileref to working dir*/
filename test list;
filename test clear;

which in my case gave:

1
2    %put *%sysfunc(pathname(WORK))*;
*C:\SAS_Temporary_Files\_TD4300_H48LBFI12PS0510_*
3    %put *%sysfunc(DLGCDIR(%sysfunc(pathname(WORK))))*;
NOTE: The current working directory is now "C:\SAS_Temporary_Files\_TD4300_H48LBFI12PS0510_".
*0*
4
5    filename test "."; /*fileref to working dir*/
6    filename test list;
NOTE: Fileref= TEST
      Physical Name= C:\SAS_Temporary_Files\_TD4300_H48LBFI12PS0510_
7    filename test clear;
NOTE: Fileref TEST has been deassigned.

 

One disadvantage, it requires SAS 9.4M5 (or 4) to work.

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

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
  • 7 replies
  • 1032 views
  • 0 likes
  • 5 in conversation