BookmarkSubscribeRSS Feed
Ryanb2
Quartz | Level 8

I've used base SAS for 15 years and now I'm moving to Viya.  In base SAS I use a lot of %include statements to run other SAS programs from a SAS program, for example:

%include 'C:/sample_sas_code.sas';

runs sample_sas_code.sas from my sas program

 

However, when I try using the %include statement in Viya to run code I stored in my snippets folder I keep getting "ERROR: physical file does not exist".  I right click on the SAS program and select "insert as path" so I'm pretty sure the path is correct.  I'm guessing this is common knowledge but I've been googling this for a while and haven't been able to find the right word combination to find out how to achieve this in SAS Viya.  I've seen mention that %include doesn't work in Viya but maybe just not in CAS(?).  Is there someone who can point me in the right direction?

22 REPLIES 22
BrunoMueller
SAS Super FREQ

You have stored your SAS program in a SAS Content folder. In order to access files from this location, you will need to use a FILENAME statement with a specific file access method. See this example below.

 

filename mypgm filesrvc folderpath="/Users/<your-userid>/My Folder/My Snippets";
%include mypgm(simple);

See the doc about FILESRVC  for more information. Make sure you look at the SAS Viya version that you use. 

Ryanb2
Quartz | Level 8

Thanks for the reply BrunoMueller.

 

I tried the code exactly as you provided after replacing my userid (see below) but I'm getting an error message when running the filename statement: 

ERROR: Folder denoted by path '/Users/ryanb/My Folder/My Snippets' was not found.
ERROR: Error in the FILENAME statement.

 

 

filename mypgm filesrvc folderpath="/Users/ryanb/My Folder/My Snippets";

 

I also right clicked on the My Snippets folder and selected "insert as path" and verified I was using the correct path.

 

 

 

MAGG
Obsidian | Level 7

You are missing one argument

filename mypgm filesrvc folderpath="/Users/ryanb/My Folder/My Snippets" filename="your_program.sas";

 

filename ffile FILESRVC folderpath='your_folder_content_path' filename='your_program.sas';
%include ffile / source;
filename ffile clear;

 

Ryanb2
Quartz | Level 8

Thanks for your suggestion, MAGG.  I tried adding the sas program as you described but I'm still getting the same error message. 

BrunoMueller
SAS Super FREQ

If your code is stored as a snippet, it is not a simple .sas file. But stored as a .csm file, see screenshot below.

BrunoMueller_0-1707381717855.png

simple.sas can be executed as shown above. The files with the .csm extension stored an XML structure that contain the code and other information.

 

So if you want to %include code stored in SAS Content, it is best to store it as plain SAS program code.

Ryanb2
Quartz | Level 8

Thanks for the reply BrunoMueller.  I moved my code to another folder but I'm still getting the same error message.  The error message indicates a problem with the path.  Whether I try the filename statement with or without referencing the SAS code I get the same message so I don't think this is about the file extension.  When I right click my program and select properties it has a sas extension and the type is SAS Program.  

 

filename ffile FILESRVC folderpath='/Users/ryanb/My Folder/SAS_FILES' filename='program.sas';
%include ffile / source;
filename ffile clear;
ERROR: Folder denoted by path '/Users/ryanb/My Folder/SAS_FILES' was not found.
ERROR: Error in the FILENAME statement.

 

 

MAGG
Obsidian | Level 7

Could you try if you can acces a other sas-file in '/Users/ryanb/My Folder' ? So you can check you've access to the grandparent folder.

BrunoMueller
SAS Super FREQ

Please add a screenshot of the Explorer pane in SAS Studio for the folder in question so that we can see what it looks like and what kind of files are in the folder. Since you could save files to this folder access permissions should be ok.

 

You can also add the debug=http option to the FILENAME statement to get more details on what is failing

filename mypgm
 filesrvc
 folderpath="<your-folder>"
 debug=http
;

Send the complete log.

Ryanb2
Quartz | Level 8

Thanks, BrunoMueller.  I think this image includes everything you mentioned.  

 

Ryanb2_0-1707526806336.png

 

Quentin
Super User

Linux paths are case sensitive.  

 

From the screenshot, it looks like the path may be /Users/RYANB/... instead of /Users/RyanB/...

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Patrick
Opal | Level 21

@Ryanb2 The code you run works in my environment. I can also replicate the error you encounter by using an invalid path. 

 

Question: If you run below code does this return RYANB?

%put &=sysuserid;
MAGG
Obsidian | Level 7

 

You could try insert as path feature from SAS-studio. So you are sure you are rigth on the capitals

MAGG_0-1707568520648.png

 

Ryanb2
Quartz | Level 8

Thanks for the suggestion.  Sorry.  I was doing some masking so I doctored the image a bit.  I always use the insert as path option so case and path should not be the issue.  

BrunoMueller
SAS Super FREQ

Check the value of the SERVICESBASELURL option, using this code:

proc options option=servicesbaseurl;
run;

Does the URL match the URL used by SAS  Studio? The port number might be missing from the SAS Studio URL.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Discussion stats
  • 22 replies
  • 4199 views
  • 23 likes
  • 6 in conversation