Doing More with Data Management |
Sometimes numeric data is stored in columns that have character data types. In order to do calculations with this numeric data, you must convert the character columns to numeric. You can use Subset/Copy on the Data Management menu to change a column from a character to a numeric format. In this section, you convert the character column DAY, which is found in the ORANGES table, to a numeric column. The value in the character column DAY is a (character) number from 1 to 6 .
Additional Information |
For additional information on changing columns from character to numeric and vice versa, refer to the PUT and INPUT functions and formats and informats in SAS Language Reference: Dictionary.
Instructions |
Follow this selection path:Tasks Data Management Subset/CopyThe Subset or Copy a Table window appears.
Subset or Copy A Table Window
Select Output Table. The Output Table or View window appears.
Type ORANGNUM in the Table/View field.
ORANGNUM is a new table that you create to contain the new numeric column DAYNUM. By leaving the defaults of Temporary and Table selected, you create a temporary table in the WORK library, which is deleted when you exit SAS. An indicator next to Temporary and Table shows that these items are selected.
Select Define new columns. The Define New Columns window appears.
Define or Modify a Column Window
You use this window to define the new columns that you are adding to the output table.
Select Initialize. The Enter Numeric Expression window appears.
Enter Numeric Expression Window
You use this window to build an expression that is used to define the new column.
Select Function. The Select the Type of Function window appears.
Select Type of Function Window
Select Character functions. The Select Data window for character functions appears.
Select Character Function Window
Select INPUT(c,ifmt). The Specify Arguments to a Function window appears.
Specify Arguments to a Function Window
You select INPUT(c,ifmt) because the source column DAY is character.
In the Value for parameter field next to CHAR, type DAY .
In the Value for parameter field next to INFORM, type 2.1 .
You type DAY in the CHAR parameter field because you want to use the values of the DAY column in the ORANGES table as the source for the DAYNUM column that you are creating.
The informat 2.1 is used in this example so you can check to see that this task completed correctly. However, you can use any valid informat. In this example, if you select a format such as 1., the only indication that the new column is numeric is that it is right justified when displayed in the FSVIEW window. However, if you use 2.1 as an informat, the new column DAYNUM is right justified and converted to display tenths.
Select OK four times until you return to the Subset or Copy a table window.
Follow this selection path:Run SubmitWhen prompted, select OK, then Goback to view the new table.
The new DAYNUM column is created, and the data is copied to the output table. An FSVIEW window appears with the data in the output table.
Scroll to the right or use the RIGHT command or function key to see the new column DAYNUM.
New DAYNUM Column
To confirm that the column is numeric, browse the properties of the table. See Altering the Properties of a SAS Table for more information.
To exit theFSVIEW window, follow this selection path:File Close
You can use the above procedure to convert character dates and times to SAS date and time values. In the Specify Arguments to a Function window, specify an appropriate date, time, or datetime informat for INFORM. For example, if you have a column of character dates in the form 05MAR1999, use the DATE9. informat. In the Define or Modify a Column window, you might want to specify an appropriate date, time, or datetime format by selecting Format.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.