As you use the Query Builder task in SAS Enterprise Guide, you might notice that it refers to tables and computed columns using names that are different than you expect. For example, instead of a table named CANDY_SALES_HISTORY, the Query Builder might show t1. This is called an alias, and it's like a nickname for the table. An alias can be handy for reducing a long, complex name to something simple to remember and type. For folks who create queries the hard way (writing their own programs), using aliases can help insulate their programs from table and column name changes, because then the names need to change in just one place instead of throughout the program. SAS Enterprise Guide generates queries that use aliases because it's generally regarded as good practice and it makes those generated programs reusable in other situations.
Here is an example SQL program with a simple inner join; it combines two tables matching up only the records where custid in one table matches the value of customer in another table. This example uses an alias for each table name (t1 and t2). An alias is a convenient syntactical shortcut. Using aliases, we don't have to repeat the name of the input tables multiple times in the program.
proc sql; create table Combined as select t1.name, t2.units from candy.candy_customers as t1 inner join candy.candy_sales_history as t2 on (t1.custid = t2.customer); quit; |
1 Comment
I'm not convinced that writing your own program is strictly the "hard way". Changing aliases in the SAS Enterprise GUI does not update all references to the old table alias. Rather, the user must go through the process flow and manually update these references. This is disappointing, since changing a table alias could be accomplished with a single replace action when writing your own program.