From the course: SAS® 9.4 Cert Prep: Part 04 Preparing Data

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Demo: Conditional processing with IF-THEN

Demo: Conditional processing with IF-THEN - SAS Tutorial

From the course: SAS® 9.4 Cert Prep: Part 04 Preparing Data

Demo: Conditional processing with IF-THEN

- [Instructor] Often in the data step we need to process data conditionally. In other words, if some condition is met, then execute one statement. If a different condition is met, then execute another statement. We can accomplish this using if-then logic. This syntax is intuitive because it uses natural language. We do if-thens all the time. For example, if it's raining, then you take your umbrella. Let's look at this example code that's reading the sashelp.cars table. In the cars2 table, we want to create a new column named Cost_Group and assign a number to the column based on the value of MSRP which represents the manufacturer's suggested retail price. We need to use conditional logic to do this. After the keyword if, we provide a condition, MSRP less than 30,000. If the condition is true, then execute a single data step statement. Assign the value one to the new column Cost_Group. A second if-then statement evaluates…

Contents