BookmarkSubscribeRSS Feed
Billybob73
Quartz | Level 8

Hi

I have a question which I'm not sure whether this is actually possible.

Let's say you have over a 1000 sas programs stored on a network drive spread over many different folders.

And you have to change a fixed thing within these programs, f.i.

libname testlib z:\networkfolder1\networkfolder2

should be :

libname testlib y:\networkfolder1\networkfolder2

 

Is this possible from another SAS program somehow without opening every individual program ?

Thanks

Regards

B

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Yes, I have written code in a previous job that does this. Basically, you read each line of text from the file, then you write each line of text to a new file with any changes that are necessary.

 

In the long run, a better solution is to create macro variables that you set in your autoexec file, that define file or server locations such as

 

 

%let myfilelocation = y:\networkfolder1\networkfolder2;

Then in your SAS code, you use &myfilelocation instead of y:\networkfolder1\networkfolder2. If the location of the files/server ever changes, you don't have to change the SAS code, you just make one change to the autoexec file.

 

--
Paige Miller
Reeza
Super User

This gets asked occasionally on here. 

 

As @PaigeMiller suggested, removing the libname is a better method in the long run so you never have to repeat this. 

 

https://communities.sas.com/t5/Base-SAS-Programming/Searching-SAS-code-for-keywords/m-p/390472#M9367...

SASKiwi
PROC Star

It's for exactly this scenario that shared SAS libraries should be defined and stored in SAS metadata via SAS Management Console removing the need to store them in programs at all. Of course this is only an option if you have a remote SAS server that is metadata enabled. Otherwise the @PaigeMiller solution is good.

 

I suggest you consider removing the shared libnames from your SAS programs and replacing them with metadata-defined ones. That means if you need to change them in the future you only need to do it in one place - SAS Management Console.

 

 

 

 

Billybob73
Quartz | Level 8

Hi,

These aren't the answers I was looking for. The library assignment was just an example.

Let's say I'd like to replace any fixed thing that is in a lot of files.

How would I proceed if I had like a 1000 programs.

Regards

B

Tom
Super User Tom
Super User

@Billybob73 wrote:

Hi,

These aren't the answers I was looking for. The library assignment was just an example.

Let's say I'd like to replace any fixed thing that is in a lot of files.

How would I proceed if I had like a 1000 programs.

Regards

B


Write a program to modify the files. SAS programs are just text files.

What we did years ago was make a program that would process one file.  It would look for particular patterns (like LIBNAME, FILE, INFILE statements).  It would convert the original line to a comment and generate a new line.

Users could then manually check and save the results.

 

To run it for a 1000 programs just use another program to generate the list of files to process and then call the first program for each file.

 

You can do it all in SAS or do it all with some other tool.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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