SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Variables
Assigning Values Conditionally


In the previous section, you created the variable TotalLoan by adding loan payments with a sum statement. This time, let's create a variable for the type of loan (variable rate or fixed rate) that will be based on the value of the existing variable Code. The value of Type will be assigned conditionally:


if Code isthen Type is
1 Fixed
2 Variable


To perform an action based on a condition, use an IF-THEN statement. The IF-THEN statement executes a SAS statement when the condition in the IF clause is true.


General form, IF-THEN statement:
IF expression THEN statement;

where

  • expression is any valid SAS expression.
  • statement is any executable SAS statement.


For example, to assign the value Fixed to the variable Type when the value of Code is 1, add the following IF-THEN statement to your DATA step:
     data finance.newloan;
        set finance.records(drop=amount rate);
        TotalLoan+payment;
        if code='1' then Type='Fixed';
     run;


SAS software executes the assignment statement only when the condition (Code=1) is true.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement