Alias: A table by any other name

1

An alias in the query builderAs 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;
Tags SAS tips
Share

About Author

Chris Hemedinger

Director, SAS User Engagement

+Chris Hemedinger is the Director of SAS User Engagement, which includes our SAS Communities and SAS User Groups. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies

1 Comment

  1. Matthew Hamilton-Smith on

    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.

Back to Top