Desktop productivity for business analysts and programmers

Issues with %include and defining library

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 6
Accepted Solution

Issues with %include and defining library

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


Accepted Solutions
Solution
a week ago
Super User
Posts: 7,444

Re: Issues with %include and defining library

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
New Contributor
Posts: 2

Re: Issues with %include and defining library

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.

Super User
Super User
Posts: 7,720

Re: Issues with %include and defining library

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.

Solution
a week ago
Super User
Posts: 7,444

Re: Issues with %include and defining library

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 6

Re: Issues with %include and defining library

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

Super User
Posts: 7,444

Re: Issues with %include and defining library


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 141 views
  • 3 likes
  • 4 in conversation