BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LarryWang
Fluorite | Level 6

I'm new to SAS but have other programming background

University Edition in Windows.

I realized that if I use

infile '/folders/myfolders/cody/learn/bankdata.txt';

the program won't work if I change any of the folder names, or if I move the .sas and .txt files together to a different folder.

Is there a way to refer to the data file in the same folder without using the full physical path?

Thanks in advance.

P.S. I've searched around a bit but in vain.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

That post doesn't answer your question as far as I understand it and your example.

 

A quick google search came up with this though, which means that the working directory issue in SAS is gone to some degree. One issue is that SAS _may_ output temporary files to the same location so you'll need to be careful. 

 

https://blogs.sas.com/content/sgf/2018/05/18/how-to-change-your-working-directory-for-sas-with-the-d...

View solution in original post

6 REPLIES 6
Reeza
Super User

SAS doesn't have a great concept of working directories like other programming languages (R/Python) are the comparisons. 

 

Instead you can set macro variables though that can be reused easily. 

 

I put this at the top of my programs:

 

%let working_dir = /folders/myfolders/learn/;

Then use it as:

 

infile "&working_dir/bankdata.txt";

For macro variables you need to use double quotes and consider it exact text replacement. 

 

Here's a quick tutorial on it, but I highly recommend learning data steps first and other options. 

 

UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/


Examples of common macro usage
https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

 

 

LarryWang
Fluorite | Level 6

Thank you, Reeza.

I also found a macro to find current directory path:

https://communities.sas.com/t5/SAS-Communities-Library/Find-current-directory-path/ta-p/485785

But it doesn't seem to work with University Edition, which runs on a virtual machine.

I got:

curdir = /opt/sasinside/SASConfig/Lev1/SASApp

which I have no idea about.

 

Larry

Reeza
Super User

That post doesn't answer your question as far as I understand it and your example.

 

A quick google search came up with this though, which means that the working directory issue in SAS is gone to some degree. One issue is that SAS _may_ output temporary files to the same location so you'll need to be careful. 

 

https://blogs.sas.com/content/sgf/2018/05/18/how-to-change-your-working-directory-for-sas-with-the-d...

LarryWang
Fluorite | Level 6

Thanks, again.  I think both methods would help address my initial request, in a regular version of SAS.

 

There seem to be limitations on how I can access folders in the Univ Edition.  DLGCDIR wouldn't work either.

 

Larry

Reeza
Super User

The method I initially posted works fine in SAS UE - I've used it many times.

Reeza
Super User

Actually I just tried both and they work fine in SAS UE. 

SAS UE is more like working with a SAS server edition that doesn't have access to your local drive except through your shared folder, in this case the myfolders folder or any additional shared folders you created. 

 

data _null_;
rc = dlgcdir("/folders/myfolders");
put rc;

run;

And check the log. 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 2235 views
  • 2 likes
  • 2 in conversation