DATA Step, Macro, Functions and more

Synonym

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Synonym

Could anyone please tell my whether sas enables create synonyms for datasets like  sql do for tables?

 


Accepted Solutions
Solution
‎08-31-2017 01:14 PM
Super Contributor
Posts: 441

Re: Synonym

My understanding is that ORACLE synonyms are created so that the user can reference a table without having to worry what schema that table belongs to. As previously mentioned there's no direct equivalent in SAS - the nearest you're going to get is macro varables holding the library and data set name which you set in the autoexec file.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Synonym

In proc sql you can use table alias instead of names if that what you mean. Out side of Proc SQL you might have to describe in some detail what you are attempting to do.

 

Example in proc sql of alias:

 

Proc sql;

   select a.name

   from sashelp.class as a

   ;

quit;

 

Contributor
Posts: 53

Re: Synonym

I mean somenthing like this:

 

create public synonym class

for sashelp.class;

 

and then use it  anytime

select  *  from  klasa

--------

one way of solving this probles is to assing macro variable:

 

%let class=sashelp.class;

 

data class;

set &class;

run;

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

Nevertheless, I wonder if in sas exist sth like sql`s synonyms. 

Super User
Posts: 19,855

Re: Synonym

Since there's nothing mentioned in the documentation I'm going to say it's not likely included.

http://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#n07kfcv1vbih8rn1k9...
Respected Advisor
Posts: 4,930

Re: Synonym

[ Edited ]

The closest thing there is is a SAS view:

 

data class / view=class;
set sashelp.class;
run;

Views are generally used to do some kind of transformation, not as simple aliasses.

 

PG
Super User
Posts: 11,343

Re: Synonym

I am not clear on the purpose of this question. How do you plan on using this "synonym" that a macro variable won't work?

Contributor
Posts: 53

Re: Synonym

Macro var works, however in Oracle  synonyms are stored in db, global macro variables are stored for a period of one session.

 

 

 

Super User
Super User
Posts: 7,074

Re: Synonym


Matt3 wrote:

Macro var works, however in Oracle  synonyms are stored in db, global macro variables are stored for a period of one session.

  

 


Not sure there really is a need for this in SAS.  There is not the same concept of a "database" that contains mutliple "schemas" in SAS. You just have individual datasets and you can use librefs to facilitate referring to the datasets without having to specify the full path.

 

Traditionally in SAS if you wanted to create a customized environemnt for individual projects you do that by setting up some utility macros and programs that users can use to setup a full environment with all of the librefs, filerefs, macro variables, autocall macros that they need to work on the partiular project that they need to use now.  That might be similar to the "database" concept in Oracle.

 

Perhaps if you are using SAS/BI type systems there are ways in the metadata manager to implement different "database" configurations that would allow you to create a customized environment for different projects.

Super User
Super User
Posts: 7,074

Re: Synonym

There is nothing like that in SAS.

 

There are ways to have libnames defined that persist, or are always created when you start your SAS session, like the SASHELP library in your example is always defined.

Not sure what value this synonym feature of Oracle adds anyway.

Trusted Advisor
Posts: 1,022

Re: Synonym

Not exactly as in PROC SQL, but depending on your situation, you might consider using macrovars.

 

 

%let data1=work.myoldfile;

%let data2=work.youroldfile;

 

data want;

   set &data1 &data2;

run;

Solution
‎08-31-2017 01:14 PM
Super Contributor
Posts: 441

Re: Synonym

My understanding is that ORACLE synonyms are created so that the user can reference a table without having to worry what schema that table belongs to. As previously mentioned there's no direct equivalent in SAS - the nearest you're going to get is macro varables holding the library and data set name which you set in the autoexec file.

Super User
Posts: 19,855

Re: Synonym

Posted in reply to ChrisBrooks

ChrisBrooks wrote:

My understanding is that ORACLE synonyms are created so that the user can reference a table without having to worry what schema that table belongs to. As previously mentioned there's no direct equivalent in SAS - the nearest you're going to get is macro varables holding the library and data set name which you set in the autoexec file.


Since SAS libnames only connect to a single schema (I think) would this approach even be useful in SAS?


Super Contributor
Posts: 441

Re: Synonym

Reeza - No, I wouldn't have thought it would be particularly useful - I know with base SAS libraries you can have two different physical folders in one concatenated library but I've always regarded that as a bad idea, whether you can do it with a SAS/ACCESS library to an RDBMS I don't know but I doubt that's a good idea either.
Contributor
Posts: 53

Re: Synonym

Posted in reply to ChrisBrooks

Thank you all.   Autoexec file it will be best soultion in my case . 

Super User
Posts: 11,343

Re: Synonym

Since you haven't provided much detail on how this is to be used in SAS we may be missing some options.

 

For instance, A library can refer to multiple folders. Suppose you have existing libraries   Alpha and Beta.

LIbname Omega (Alpha Beta);

Omega would contain everything in Alpha and Beta (though identically named datasets become problematic)

or

 

Libname Combine ("Path/folder1" "Path/Folder2" "OtherPath/Folder3");

could reference all of the SAS datasets in those three folders.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 14 replies
  • 247 views
  • 3 likes
  • 7 in conversation