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 is | then 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:
where
|
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;
|
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.