BookmarkSubscribeRSS Feed
NVhealth
Calcite | Level 5

Hi Everyone,

Is there a way to rename a library that has already been brought into SAS so that you only rename the library once at the beginning of your PROC SQL procedure?  I know you can use libname when you name your library, but I'm looking to take an existing library already named and rename it once.

Is this possible?

Thank you for any help or suggestions.

5 REPLIES 5
jakarman
Barite | Level 11

The libname is the same as schema/database in a RDBMS. Renaming it doesn't make any sense as it a physical defined unit for the logical collection.

You must have some logical question to solve asking this.

There is something SAS is behaving different with libnames. Concat is possible, that is having a nice approach for catalog and other sas types needing a DTAP segregation.

---->-- ja karman --<-----
NVhealth
Calcite | Level 5

I'm very new to SAS and so I am not as familiar with the right phrasing for things.

The issue that I am having is when I share code between a co-worker and myself.  He uses a different libname for the same database source than I use.  Instead of bringing the same database source in twice (using libname for my naming convention and another libname for his) I thought there must be an easier way to just take the libname, call it into my procedure at the beginning, and only need to rename it in one spot.  I hate doing a search and replace for the library within the code.  Seems inefficient.  I don't like the libnames that he uses because they don't mean as much to me when I'm coding because the two libraries are very different with what I pull from them.

Is that a better clarification?

=========

I found the answer.  I used a macro:

%Let NewDB = OldDB;

----------------

Then in my proc sql procedure under From I did

From

     &NewDB..First_Name  (the ampersand and the two periods were essential to get it to read the macro)

This pulled in the data from the OldDB library and it let me name it as NewDB when I was programming.

SASKiwi
PROC Star

If you want to point to the same SAS library as your co-worker but with a different LIBREF (library name) then use a LIBNAME statement. What is the database source - SAS or some other database? If its SAS then this might help:

libname coworker '\\ServerName\SASfolder';

libname mylib     '\\ServerName\SASfolder'; <== Note different LIBREF but both point to same folder of SAS datasets.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Personally speaking if you want to use differeing libnames from co-workers then that is a problem.  Generally speaking libnames should be setup as part of a generic start program, and then the whole company would use them.  Otherwise every time someone else opens your programs, they may have to setup libnames - remember, coding standards, defaults, company policy, and good programming practices are not just for your benefit, but for everyone who has contact with it.

jakarman
Barite | Level 11

NVHealth, Great to see you have found a way out. Your question is about setting coding standards with good practice.

The libname/filename statements are transforming physical to logical naming standards.
You should isolate those to some place at a start of code moment. The goal is to have those defined at one easy to maintain and exchange place. By that you can doe your coding without knowing the hardware and environment. This makes versioning and release management easy.
The usage of the SAS macro language is a good tool for this (setting environment namings not coding).

The usage of macrovariable names for the  different used  names is an approach.  Another would be using duplicated libnames/filenames. And have those naming being slowly in time converted. A duplicate libname is easy, you could think an many options to be set at the libname/filename .
It is the same as SASkiwi but coded different.

    libname coworker '\\ServerName\SASfolder';

    libname mylib "%sysfunc(pathname(coworker)) "; 

When libnames become meaningfull and are getting a part of your metadata. You should set some naming standards with a context. It is not inefficient to standardize, it is setting the context meaning of your code getting is understandable and reusable by others. Of couse in one time coding an throw away approach there is no need for that. .    

---->-- ja karman --<-----

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2414 views
  • 1 like
  • 4 in conversation