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

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?

 

1 ACCEPTED SOLUTION
13 REPLIES 13
ErikLund_Jensen
Rhodochrosite | Level 12

Hi

 

Have you tried using a sas Zip filename instead.?

LFern
Obsidian | Level 7

No I haven't. I thought the zip filenames were for ".sas7bdat" files with data rather than ".sas" programs with code.

ErikLund_Jensen
Rhodochrosite | Level 12
Please excuse me. By mistake I answered a wrong question.
LFern
Obsidian | Level 7

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.

LFern
Obsidian | Level 7

Another user just informed me what you meant by %include and how that achieves what I want! Thank you again!!

Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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.

SASKiwi
PROC Star

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.

Satish_Parida
Lapis Lazuli | Level 10

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)

LFern
Obsidian | Level 7

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!

andreas_lds
Jade | Level 19

You can use %include  (already suggested by @Kurt_Bremser )

%include "\\path\autoexec.sas";
LFern
Obsidian | Level 7

AHHHHH that's perfect!!! Thank you so much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1406 views
  • 1 like
  • 7 in conversation