Could anyone please tell my whether sas enables create synonyms for datasets like sql do for tables?
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.
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;
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.
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.
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?
Macro var works, however in Oracle synonyms are stored in db, global macro variables are stored for a period of one session.
@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.
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.
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;
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.
@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?
Thank you all. Autoexec file it will be best soultion in my case .
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.