Can I change my current folder in SAS so that I don't need to type the folder path repeatedly? I have a couple of processes that I would like to run and save separately using ODS.
But please keep in mind that I don't want to reset my "default folder". I have several projects, so I would like to know how to move a current folder in SAS.
What I can do now:
ods html file ="c:\folder1\folder2\folder3\folder4\filename1.htm";
*first procedure;
ods html file ="c:\folder1\folder2\folder3\folder4\filename2.htm";
*second procedure;
ods html file ="c:\folder1\folder2\folder3\folder4\filename3.htm";
*third procedure;
I would like to change the above code to the below.
ods html file ="filename1.htm";
*first procedure;
ods html file ="filename2.htm";
*second procedure;
ods html file ="filename3.htm";
*third procedure;
@braam - I would consider it best practice to follow @PaigeMiller 's and @Reeza 's recommendation of storing absolute folder paths in macro variables at the start of your SAS application/program. Set it once, then use it everywhere. Then you don't need to worry about current folders at all and whether you are in the 'right' one or not. Good practices like this become even more important when using SAS on remote servers where folder organisation is more complex.
@braam wrote:
Can I change my current folder in SAS so that I don't need to type the folder path repeatedly? I have a couple of processes that I would like to run and save separately using ODS.
But please keep in mind that I don't want to reset my "default folder". I have several projects, so I would like to know how to move a current folder in SAS.
What I can do now:
ods html file ="c:\folder1\folder2\folder3\folder4\filename1.htm"; *first procedure; ods html file ="c:\folder1\folder2\folder3\folder4\filename2.htm"; *second procedure; ods html file ="c:\folder1\folder2\folder3\folder4\filename3.htm"; *third procedure;
I would like to change the above code to the below.
ods html file ="filename1.htm"; *first procedure; ods html file ="filename2.htm"; *second procedure; ods html file ="filename3.htm"; *third procedure;
I'm not sure why you need to move a folder to achieve anything. If you have a folder that you always use for a specific project, you can change the AUTOEXEC to set a macro variable taht contains the folder used for each project.
So in your autoexec file, if you have a project named "GAZELLE", you can set the macro variable like this:
%let gazelle=c:\folder1\folder2\folder3\folder4;
and then your program can access this folder as
ods html file ="&gazelle\filename1.htm";
The nice thing about this, is that if your servers or hard disks ever change (our server names change from time to time) you just have to change the autoexec; you don't have to change all of the locations in all of the programs that use this folder.
Also, you can combine this with @Kurt_Bremser 's suggestion:
rc=dlgcdir("&gazelle");
Thanks for your suggestions. Unfortunately, I encountered an error message when I executed DLGDIR. Perhaps there is a version issiue with my SAS.
3769 data _null_;
3770 rc=dlgcdir();
-------
68
ERROR 68-185: The function DLGCDIR is unknown, or cannot be accessed.
3771 put rc=;
3772 run;
I happened to find a way to achieve what I wanted to do using x statement.
x 'cd C:\folder1\folder2';
I confirmed that things work as I expected after this x statement.
Thanks again!
@braam - I would consider it best practice to follow @PaigeMiller 's and @Reeza 's recommendation of storing absolute folder paths in macro variables at the start of your SAS application/program. Set it once, then use it everywhere. Then you don't need to worry about current folders at all and whether you are in the 'right' one or not. Good practices like this become even more important when using SAS on remote servers where folder organisation is more complex.
Looks like you are running an older version of SAS.
sets the working directory.
This function is available beginning with the December 2017 (9.4M5) release.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.