When you want to conditionally process a data set (such as creating a new variable based on a condition), you typically think of using IF-THEN logic, but IF-THEN logic is only valid in DATA step. In SAS Enterprise Guide, the Query Builder uses PROC SQL behind the scenes. In PROC SQL, the CASE statement is used to do conditional processing.
In SAS Enterprise Guide 4.2, the method of using the CASE statement has changed. This sample introduces you to those changes by explaining how to create a new variable named TYPE that is based on the value of a variable named CODE. Specifically, if CODE=1, then TYPE is equal to 'Fruit'. If CODE=2, then TYPE is equal to 'Vegetable'.
Note: For an example of using the CASE statement in SAS Enterprise Guide 4.1, see Sample 32160.
Here is the SAS code that is used to create the sample data set.
data produce; input name $ code; cards; banana 1 apple 1 lettuce 2 carrot 2 pepper 2 orange 1 potato 2 corn 2 grape 1 mango 1 ; run;
CASE WHEN t1.code = 1 THEN 'Fruit' WHEN t1.code = 2 THEN 'Vegetable' ELSE 'other' END
For more information about using SAS Enterprise Guide, see the SAS Enterprise Guide documentation page.
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.
In SAS Enterprise Guide 4.2, the method of using the CASE statement has changed. This sample introduces you to those changes by explaining how to create a new variable based on a condition.
Type: | Sample |
Date Modified: | 2010-01-06 14:09:24 |
Date Created: | 2009-12-23 14:12:56 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
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 XP Professional | 4.2 | 9.2 TS2M0 | ||||
Windows Vista | 4.2 | 9.2 TS2M0 |