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

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

@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.

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@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");
--
Paige Miller
braam
Quartz | Level 8

@PaigeMiller @Kurt_Bremser 

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!

 

Reeza
Super User
I recommend PaigeMiller's solution. I always have a working path set in my main/control program and then all paths after are relative so if I move the whole project I'm not retyping paths manually in multiple places. Plus I also have a system for how my files are stored and this helps to enforce it.
SASKiwi
PROC Star

@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.

Tom
Super User Tom
Super User

Looks like you are running an older version of SAS.

DLGCDIR

sets the working directory.

This function is available beginning with the December 2017 (9.4M5) release.

 

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1637 views
  • 9 likes
  • 6 in conversation