Sample 42038: Adding an IF-THEN condition when creating a new column in the Data Grid of SAS® Enterprise Guide®
Overview
If you have write access to a SAS data set, then you can use the Data Grid in SAS Enterprise Guide to create a new column using an expression such as:
However, entering an IF-THEN condition, or any other valid SAS statement, generates an error because this feature is designed to allow only the right side of an expression.
This sample explains how to include an IF-THEN condition in order to create a new character column based on the values of a numeric column. However, the same technique can be used to enter any valid DATA step statement when adding a new numeric or character column in the Data Grid.
This sample uses a copy of the CLASS data set from the SASHELP library.
Creating the column
- Open a test data set for which you have update access.
- Select Edit menu and then deselect Protect Data.
- Click Yes to switch to Update mode.
- Select Edit ► Columns ► Insert.
- Enter a column name, and, if necessary, change the column type.
- Enter an expression according to the following guidelines.
The key to this technique is the first line of the code, which closes off the code that is generated by SAS Enterprise Guide. Closing off the SAS Enterprise Guide code enables you to add the DATA step code.
If the new column is Character, as in this sample, then use '.';
If the new column is Numeric, then use .;
'.' ;
if Age < 13 then AGE_CODE = 'A';
else if Age = 13 then AGE_CODE = 'B';
else if Age > 13 then AGE_CODE = 'C';
|
|
The following display shows the Insert column dialog box.
- Click OK to run.
Viewing results
The following display shows the resulting SAS data set with the new column called AGE_CODE.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample explains how to include an IF-THEN condition in order to create a new character column based on the values of a numeric column. The same technique can be used to enter any valid DATA step statement when adding a new numeric or character column in the Data Grid.
Date Modified: | 2011-01-20 13:24:50 |
Date Created: | 2011-01-06 13:46:51 |
Operating System and Release Information
SAS System | SAS Enterprise Guide | Microsoft® Windows® for x64 | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Standard Edition | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows Server 2003 for x64 | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows Server 2008 for x64 | 4.2 | | 9.2 TS2M0 | |
Microsoft Windows XP Professional | 4.2 | | 9.2 TS2M0 | |
Windows Vista | 4.2 | | 9.2 TS2M0 | |
Windows Vista for x64 | 4.2 | | 9.2 TS2M0 | |