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

I am basically having the same issue with `%include` and defining a library as seen here.

 

I have the following two lines in my SASGrid program:

    %include "\C:\Users\jhggg\Documents\SAS_Code\base.sas";
    libname libr "/users/fcgdf/data/models/new_model/libr";

 

And they are resulting in the errors: `Error: Cannot open %include "sasuserhome/jhggg/\C:\Users\jhggg\Documents\SAS_Code\base.sas` and `Library libr does not exist`. I am not too sure why these are cropping up. I've read that it has to do with the actual file destinations, but `base.sas` is actually located at \C:\Users\jhggg\Documents\SAS_Code\base.sas. Looking at the link, I am not too sure how to get the UNC path.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When your path gets expanded like that:

"sasuserhome/jhggg/\C:\Users\jhggg\Documents\SAS_Code\base.sas"

it is a sign that your SAS runs on a UNIX server. In UNIX, the backslash has a completely different meaning from what it means in Windows.

Using the backslash as directory separator is a remnant from the way DOS was cobbled together from radically different programs (codebase from CP/M, hierarchical filesystem from UNIX).

 

Your SAS session, running on a remote UNIX server, will most probably not have any access to your desktop's filesystem, especially the root of your C:\ drive. Unless you find a shared resource that can be accessed (by using a UNC) from both your desktop and your SAS server, you will have to store the .sas file on your SAS server (easy with Enterprise Guide), and then include it from there.

 

Example for EG:

- in the default config, "Files" in the EG server list points to your home directory

- when you save base.sas there, you can include it by simply doing

%include "base.sas";

or, to be even more elegant

%include "$HOME/base.sas";

$HOME is a UNIX environment variable that holds the "absolute" (starting at the root directory) path to your home directory.

View solution in original post

5 REPLIES 5
andrewboyd
Fluorite | Level 6

Looks like you are trying to reference a locally stored file when running SAS on a remote server. You need to save your code to the remote server and then reference the full unix file path in the %include. Your libref will also need to be relevant to the unix host you are executing your code on.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

First off, the include statement - 

%include "\C:\Users\jhggg\Documents\SAS_Code\base.sas";

                 ^

The marked character is invalid, paths start with a letter, then a colon. then a slash.  

 

 

This:
    libname libr "/users/fcgdf/data/models/new_model/libr";

 

Indicates a server based system.  Decide which you are using an put the include file in the correct server area, and ensure that the given area exists, is typed correctly and fully, and you have access to that area.

Kurt_Bremser
Super User

When your path gets expanded like that:

"sasuserhome/jhggg/\C:\Users\jhggg\Documents\SAS_Code\base.sas"

it is a sign that your SAS runs on a UNIX server. In UNIX, the backslash has a completely different meaning from what it means in Windows.

Using the backslash as directory separator is a remnant from the way DOS was cobbled together from radically different programs (codebase from CP/M, hierarchical filesystem from UNIX).

 

Your SAS session, running on a remote UNIX server, will most probably not have any access to your desktop's filesystem, especially the root of your C:\ drive. Unless you find a shared resource that can be accessed (by using a UNC) from both your desktop and your SAS server, you will have to store the .sas file on your SAS server (easy with Enterprise Guide), and then include it from there.

 

Example for EG:

- in the default config, "Files" in the EG server list points to your home directory

- when you save base.sas there, you can include it by simply doing

%include "base.sas";

or, to be even more elegant

%include "$HOME/base.sas";

$HOME is a UNIX environment variable that holds the "absolute" (starting at the root directory) path to your home directory.

Sid9
Fluorite | Level 6

Thank you very much. I have now corrected the "%include" comment accordingly. I was just wondering if you could please guide me on how I would need to correct the second statement "libname libr "/users/fcgdf/data/models/new_model/libr";".

 

Thanks

Kurt_Bremser
Super User

@Sid9 wrote:

Thank you very much. I have now corrected the "%include" comment accordingly. I was just wondering if you could please guide me on how I would need to correct the second statement "libname libr "/users/fcgdf/data/models/new_model/libr";".

 

Thanks


First, I'd consult with the person who gave me that library path. If you want to assign a library to a directory you created, you need to make sure that SAS and the tool you used to create that directory work in the same context (same user, same server). If someone wants you to access a directory in their home path, you might not have the necessary permissions to go looking there.

So there are multiple possible reasons for your problem. We will need more information about your setup.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 4994 views
  • 3 likes
  • 4 in conversation