Previous Page | Next Page

Defining a New Column

Defining a New Column


Instructions

  1. To define a new column, selectTasks [arrow] Data Management [arrow] Subset/CopyThe Subset or Copy a Table window appears.

    Subset or Copy a Table Window

    [Subset or Copy a Table Window]

    When you define a new column, you use Subset/Copy because the existing table is copied and the newly defined column is created to generate the output table.

  2. If the active table is SASUSER.HOUSES, then 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.

  3. If other report selections exist (for example, column names are listed for Define new columns), then selectFile [arrow] Newto clear these selections.

  4. Select Output data from the Subset or Copy a Table window. The Output Table or View window appears.

    Output Table or View Window

    [Output Table or View Window]

    An output table enables you to store the data with the new column separate from the original data.
  5. 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.  [cautionend]

  6. 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.

  7. 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.

  8. Select OK. The Subset or Copy a Table window reappears.

  9. 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

    [Define or Modify a Column Window]

  10. In the Column field, type FOOTCOST as the name of the new column. See SAS Tables for details on naming columns.

  11. Select Numeric as the type of the column.

    A column can be character or numeric. If a column is defined as character, then it can contain letters, numbers, special characters, and symbols, but it cannot be used in arithmetic calculations. If a column is defined as numeric, then it can contain only numbers, decimal points, plus signs, and minus signs, and it can be used in arithmetic calculations.

  12. 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.

  13. Select Format. The Select Numeric Format window appears.

    Select Numeric Format Window

    [Select Numeric Format Window]

    A format is a pattern that SAS uses to determine how a column value should be displayed. SAS 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.

  14. Select the DOLLARw.d format. The Specify Format Widths window appears with the default definition for the selected format.

    Specify Format Widths Window

    [Specify Format Widths Window]

  15. 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.

  16. 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

    [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, then the items that are available for selection are highlighted while you are building the expression.

  17. 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.

  18. Select the division symbol (/).

  19. 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.

  20. Select OK. The Define or Modify a Column window reappears with the new column defined.

    Definition of the FOOTCOST Column

    [Definition of the FOOTCOST Column]

    Select OK. The Define New Columns window appears with information about the new column.

    Define New Columns Window

    [Define New Columns Window]

    Select OK again. The Subset or Copy a Table window reappears.

  21. To copy the data into the new table and generate the new column, selectRun [arrow] SubmitThe 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

    [HOUSCOST Table]

  22. When you finish looking at the new table, follow this selection path to return to the Subset or Copy a Data Set window: File [arrow] Close


Exiting This Task

When you are ready to return to the WorkPlace menu or move on to another task, follow the directions in Exiting a Task.

Previous Page | Next Page | Top of Page