Hello,
Suppose in my desktop I have a SAS 9.3 program called "step1.sas".
Step1.sas uses the following libpath:
libname LOCATION1 "C:\Users\Desktop\year2014\";
In another SAS program called "step2.sas", is it possible for me to read the libname path from step1.sas? This script definitely isn't right, but essentially this is the libpath I want in step2.sas:
libname LOCATION1 "C:\Users\Desktop\step1.sas where libname='LOCATION1' ";
Ultimately, I'm trying to get step2.sas location1 = step1.sas location1 = "C:\Users\Desktop\year2014\"
Thoughts?
If you need library references across multiple programs, put the libnames into the autoexec or into an include.
Hi
Have you tried using a sas Zip filename instead.?
No I haven't. I thought the zip filenames were for ".sas7bdat" files with data rather than ".sas" programs with code.
If you need library references across multiple programs, put the libnames into the autoexec or into an include.
Thank you for informing me about the autoexec option! It's exactly the kind of premise I'm going for.
The only problem with it is that it requires a user to change the properties of sas (the target path). Ideally though, I'd like for anyone to open up any sas they have and run a program that is able to read a masterlist of libnames WITHOUT first changing the settings. Do you know of a way to invoke an autoexec file with a line of code instead of changing the target path? For example, at the top of step1.sas, a line of code that says "read in libnames from autoexec.sas"?
Again, the autoexec is exactly what I'm going for...I'm using hoping to automate its function without users changing their settings.
I appreciate any help I can get.
Another user just informed me what you meant by %include and how that achieves what I want! Thank you again!!
There are a lot of things you can do to make the startup process dynamic. I have a piece of code in the autoexec_usermods.sas file of our workspace server that looks for a file called egauto.sas in the current user's home directory and includes it if found. This allows users to store personalizations centrally, and not lose settings when they get a new desktop computer.
Are you asking how to read a SAS program and figure out if it defined a libref?
Or perhaps read as SAS log and figure out if it defined a libref?
Why not just run them both together in the same SAS session? Then when STEP2 runs LOCATION will already be defined and there is no need to try to deduce what it should be.
As long as programs step1 and step2 run in the same SAS session when you only need to assign your LOCATION LIBNAME once in step1 then just refer to it in step2.
You can read the step1.sas using infile in a data step statement and issue an if statement where libname statement appears using a findw function.
Then You can extract the lib path using a substring / scan function.
But It is not a suggested way to go, better follow the method @Kurt_Bremser mentioned. (Use AutoExec)
Hi there!
The autoexec option is similar to what I want to achieve. However, I don't want users to need to change their SAS properties (i.e., the target path).
Do you know of a way that a user can call up an autoexec file in a line of code?...such as "set \\whateverpath\autoexec.sas"
Thank you for any help on this!
You can use %include (already suggested by @Kurt_Bremser )
%include "\\path\autoexec.sas";
AHHHHH that's perfect!!! Thank you so much!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: