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.
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.
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...
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
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.
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
The method I initially posted works fine in SAS UE - I've used it many times.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.