Help using Base SAS procedures

SAS SQL ability to rename library in PROC SQL procedure?

Reply
New Contributor
Posts: 2

SAS SQL ability to rename library in PROC SQL procedure?

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.

Trusted Advisor
Posts: 3,212

Re: SAS SQL ability to rename library in PROC SQL procedure?

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 --<-----
New Contributor
Posts: 2

Re: SAS SQL ability to rename library in PROC SQL procedure?

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.

Super User
Posts: 3,250

Re: SAS SQL ability to rename library in PROC SQL procedure?

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.

Super User
Super User
Posts: 7,942

Re: SAS SQL ability to rename library in PROC SQL procedure?

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.

Trusted Advisor
Posts: 3,212

Re: SAS SQL ability to rename library in PROC SQL procedure?

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 --<-----
Ask a Question
Discussion stats
  • 5 replies
  • 475 views
  • 1 like
  • 4 in conversation