SAS Enterprise Guide sets values for several useful SAS macro variables when it connects to a SAS session, including one macro variable, &_CLIENTPROJECTPATH, that contains the name and path of the current SAS Enterprise Guide project file.
(To learn about this and other macro variables that SAS Enterprise Guide assigns, look in Help->SAS Enterprise Guide help, and search the Index for "macro variables".)
If your SAS program knows the path of your project file, then you can use that information to make your project more "portable", and reference data resources using paths that are relative to the project location, instead of having to hard-code absolute paths into your program.
For example, I've been working with some data from DonorsChoose.org, and I've captured that work in a project file. After saving the project, I can easily get the name of the project file by checking the value of &_CLIENTPROJECTPATH:
15 %put &_clientprojectpath; 'C:\DataSources\DonorsChoose\DonorsChoose.egp'
If you can get the full path of the project file, then you can build that information into a SAS program so that as you move the project file and its "assets" (such as data), you don't need to make changes to the project to accommodate a new project folder "home". Here is the bit of code that takes the project file location and distills a path from it, and then uses it to assign a path-based SAS library.
/* a bit of code to detect the local project path */ /* NOTE: &_CLIENTPROJECTPATH is set only if you saved the project already! */ %let localProjectPath = %sysfunc(substr(%sysfunc(dequote(&_CLIENTPROJECTPATH)), 1, %sysfunc(findc(%sysfunc(dequote(&_CLIENTPROJECTPATH)), %str(/), -255 )))); libname DC "&localProjectPath";
Here's the output:
21 libname DC "&localProjectPath"; NOTE: Libref DC was successfully assigned as follows: Engine: V9 Physical Name: C:\DataSources\DonorsChoose
This allows me to keep the project together with the data that it consumes and creates. And I can easily share the project and data with a colleague, who can store it in a different folder on his/her machine, and it should work just the same without any changes.

6 Comments
Hi Chris,
This works fine if EG & SAS are on the same PC (or at least map the same way to the same folder).
What are suggestions when EG & the underlying SAS are on different platforms and/or don't map to same folder?
For example:
- EG on the PC connecting to SAS on Unix
- EG project on a PC's mapped "Z:" drive connecting to SAS on a WIndows server where the equivalent folder is "D:"?
Cheers.
Yeah. I guess the problem is that the .egp is a PC format and it just will not translate to Unix in the desired way.
But awesome tip Chris!!
Actually, it can work IF you save the project to the server file system. For example, File->Save As, choose SASApp (your server), Files, and navigate to a file folder on the remote SAS server.
In that case _CLIENTPROJECTPATH is set to the path and name on the remote server, even if it's Unix. For example:
23 %put &_clientprojectpath;
'/r/server.unx.sas.com/vol/vol910/u91/sascrh/projects/SampleCars.egp'
What do I do wrong? Part of the log:
15 %let localProjectPath =
16 %sysfunc(substr(%sysfunc(dequote(&_CLIENTPROJECTPATH)), 1,
WARNING: Argument 3 to function SUBSTR referenced by the %SYSFUNC or %QSYSFUNC macro function
is out of range.
17 %sysfunc(findc(%sysfunc(dequote(&_CLIENTPROJECTPATH)), %str(/), -25 ))));
18
19 libname DC "&localProjectPath";
NOTE: Libref DC was successfully assigned as follows:
Engine: V9
Physical Name: C:\Windows\system32\
Now I ran it with SASApp but still the wrong path:
WARNING: Argument 3 to function SUBSTR referenced by the %SYSFUNC or %QSYSFUNC macro function is out
of range.
17 %sysfunc(findc(%sysfunc(dequote(&_CLIENTPROJECTPATH)), %str(/), -255 ))));
18
19 libname DC "&localProjectPath";
NOTE: Libref DC was successfully assigned as follows:
Engine: V9
Physical Name: E:\SAS\Config\Lev1\SASApp\
The CLIENTPROJECTPATH macro yields the folder name for the EGP file on your local machine. That means if your SAS workspace is remote, then you won't be able to use that path in your programs this way.
See this list of other macro variables that might be helpful for your SAS programs.
One Trackback
[...] You can use these macro variables to code various logic tricks into your programs, such as to determine where the current project file resides and assign a library to its path. [...]