You can create new columns that contain
either text or a calculation. New columns appear in output, along
with any existing columns that are selected. Keep in mind that new
columns exist only for the duration of the query, unless a table or
a view is created.
To create a
new column, include any valid SAS expression in the SELECT clause
list of columns. You can assign a column alias, a name, to a new column
by using the keyword AS followed by the name that you would like to
use.
Note: A column alias must follow
the rules for SAS names.
In the sample PROC SQL
query, shown below, an expression is used to calculate the new column:
the values of Salary are multiplied by .06. The keyword AS is used
to assign the column alias
bonus
to the new column.
proc sql;
select empid,jobcode,salary,
salary*.06 as bonus
from sasuser.payrollmaster
where salary<32000
order by jobcode;
A column alias is useful
because it enables you to reference the column elsewhere in the query.
Also, the column alias
appears as a column heading in the output.
The following output
shows how the calculated column bonus
is displayed. Notice that
the column alias bonus
appears in lowercase, exactly
as it is specified in the SELECT clause.
In the SELECT clause,
you can specify a label for an existing column or a new column. If
both a label alias and a column alias are specified for a new column,
the label is displayed as the column heading in the output.
If only a column alias is specified, it is important that you specify
the column alias exactly as you want it to appear in the output.