Usage Note 24486: How to use IF-THEN type syntax and logic in SAS® Enterprise Guide®
Yes, you can build IF-THEN syntax and logic in SAS Enterprise Guide. The Query Builder can be used to generate CASE syntax in PROC SQL which is very similar to IF-THEN logic that is available in the DATA step. Complete the following steps:
-
Select File
Open
From SAS Server/Binder, and choose the Server if it is not already selected.
-
Choose Libraries, and then select the SASHELP library.
- Select and open the CLASS data set.
- Close the data grid.
- With the data selected, select Data
Filter and Query Active Data.
- Click the Select and Sort tab.
- Click New.
- Click Change beside the Format area.
- Under Categories, choose Character.
- Under Formats, choose $w.
- Under Attributes, assign an Overall width of 10.
- Click OK.
- Assign a new name. For this example, enter Teen in the Alias field.
- Click Change beside Expression.
- In the Expression Builder, under Name, double-click CASE {else} which
populates the Expression area.
- Format the expression to match the following:
CASE WHEN <whenCondition> THEN <resultExpression>
WHEN <whenCondition> THEN <resultExpression>
ELSE <resultExpression>
END
|
- Select and remove the first <whenCondition>.
- From the Values tab, double-click Age to populate the first When
condition.
- After the When condition, enter: <=12
- Select and remove the first <resultExpression>.
- Replace it with: “Pre-Teen”
- Select and remove the second <whenCondition>.
- From the Values tab, double-click Age to populate the second When
condition.
- After the When condition, enter: >=13
- Select and remove the second <resultExpression>.
- Replace it with: “Teen”
- Select and remove <resultExpression> beside the ELSE.
- Replace it with: “Other”
- The final syntax in the Expression Builder for this example should be:
CASE WHEN CLASS.Age <=12 THEN "Pre-Teen"
WHEN CLASS.Age >=13 THEN "Teen"
ELSE "other"
END
|
- Click OK twice.
-
Click Run Query to generate the results.
You will see a new character column, Teen, with values of “Pre-Teen”
or “Teen” which are based on the values of the Age Column.
Note: These steps are based on SAS Enterprise Guide 3.0.2.446.
Operating System and Release Information
| SAS System | SAS Enterprise Guide | Windows | n/a | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
| Type: | Usage Note |
| Priority: | low |
| Topic: | SAS Reference ==> Procedures ==> SQL SAS Reference ==> SQL
|
| Date Modified: | 2007-11-30 15:42:38 |
| Date Created: | 2006-01-25 15:28:16 |