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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

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

14 REPLIES 14
ballardw
Super User

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;

 

Matt3
Quartz | Level 8

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. 

Reeza
Super User
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...
PGStats
Opal | Level 21

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
ballardw
Super User

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?

Matt3
Quartz | Level 8

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

 

 

 

Tom
Super User Tom
Super User

@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.

Tom
Super User Tom
Super User

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.

mkeintz
PROC Star

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ChrisBrooks
Ammonite | Level 13

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.

Reeza
Super User

@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?


ChrisBrooks
Ammonite | Level 13
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.
Matt3
Quartz | Level 8

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

ballardw
Super User

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 14 replies
  • 2586 views
  • 3 likes
  • 7 in conversation