-
To define a new column, follow this selection path:
Tasks |
|
Data Management |
|
Subset/Copy |
The
Subset or Copy a Table window appears.
Subset or Copy a Table Window
When you define a new
column, use Subset/Copy because the existing table is copied and the newly defined column is created to generate the output
table.
- If the active table is SASUSER.HOUSES, continue to the next step. Otherwise, select Table, and then select the SASUSER.HOUSES
table. For more information on selecting tables, see Selecting a Table.
- If other report selections
exist (for example, column names are listed for Define new columns), follow this selection path to clear these
selections:
File |
|
New |
- Select Output data from the Subset
or Copy a Table window. The Output Table or View window appears.
Output Table or View Window
An output table enables you to store the data with the
new column separate from the original data.
-
In the
Table/View field, type
HOUSCOST
as the name of the output table in which you want to store the data with the new column. See SAS Tables for details on naming SAS
tables.
Note: Use Replace if existing to replace the data in a table or view of the same name. Otherwise, you get an error message that the
table already exists and you must enter a new table name.
-
You can
store the data temporarily or permanently. For this example, store the data temporarily.
- If you want to store the data only for the length of the SAS
session, select Temporary. The data is stored in a temporary table called WORK.HOUSCOST, which is deleted when you end the SAS
session.
- If you want to store the data permanently, select Permanent. A list of existing librefs appears. Select the libref for the
location where you want to store the data, for example, the SASUSER libref. The table HOUSCOST is stored in SASUSER, and remains there until you delete
it.
- You can store the data with the new column either as a table or as a view. For this example, store the data as a
table.
- Select OK. The Subset or Copy a Table window
reappears.
- Select Define new columns from the Subset or Copy a Table window. The Define or
Modify a Column window appears.
Define or Modify a Column Window
-
In the Column field, type
FOOTCOST
as the name of the new column. See SAS Tables for details on naming columns.
- Select
Numeric as the type of the column.
A column
can be character or numeric. If a column is defined as character, it can contain letters, numbers, special characters, and symbols, but it cannot be used in arithmetic calculations. If a column is
defined as numeric, it can contain only numbers, decimal points, plus signs, and minus signs, and it can be used in arithmetic
calculations.
-
In the Label field, type
Cost per Square Foot
. A label can be up to 40 characters, and it can be printed instead of, or in addition to, the column name in certain tasks.
- Select
Format. The Select Numeric Format window appears.
Select Numeric Format Window
A format is a pattern that the SAS System uses to determine how a column value should be displayed. The SAS System provides a set of standard formats and also
enables you to define your own custom formats. For example, the DOLLARw.d default format displays the amount 1200 as $1,200. For more information on formats, refer to
SAS Language Reference: Dictionary.
- Select the DOLLARw.d format. The Specify Format Widths
window appears with the default definition for the selected format.
Specify Format Widths Window
- Select
OK to accept the defaults of 10 for the format width and 0 for the number of digits to the right of the decimal point. The Define or Modify a
Column window reappears.
-
Select Initialize from the Define or Modify a Column window. The Enter Numeric
Expression window appears. This window enables you to define (initialize) the new column.
Enter Numeric Expression
For this example, you can
determine the cost per square foot by building the arithmetic expression of price divided by square feet (PRICE/SQFEET). The cost per square foot is calculated for each house and stored in the new
column called FOOTCOST. You can build the expression by using one of the methods listed below.
- You can type the expression directly by using
EDIT THE EXPRESSION.
- You can build the expression by using items in the window. If you use the items in this window, the items
available for selection are highlighted while you are building the expression.
- To build the expression by using the items in the
window, select Column from the Enter Numeric Expression window. Select the PRICE column. For more information on selecting columns, refer to
Selecting a Column.
- Select the division symbol
(/).
- Select Column again, and then select the SQFEET column the same way you selected the PRICE column in
step 17. The Enter Numeric Expression window reappears.
- Select OK. The Define or Modify a
Column window reappears with the new column defined.
Definition of the FOOTCOST Column
Select
OK. The Define New Columns window appears with information about the new column.
Define New Columns Window
Select
OK again. The Subset or Copy a Table window reappears.
- To copy the data into the new table and generate
the new column, follow this selection path:
Run |
|
Submit |
The data from the HOUSES table is copied into the HOUSCOST table, and the new
column FOOTCOST is created. The new table is shown in a tabular format.
HOUSCOST Table
- When you finish looking
at the new table, follow this selection path to return to the Subset or Copy a Data Set window:
File |
|
Close |
When you are ready to return to the WorkPlace menu or move on to another task, follow the directions in
Exiting a Task.