Creating Variables |
Executing Multiple Statements
Conditionally |
So far, you've assigned values to Type using
IF-THEN and ELSE statements, each of which executed a single SAS statement
conditionally.
data finance.newloan; set finance.records(drop=amount rate); length Type $ 8; TotalLoan+payment; if code='1' then type='Fixed'; else type='Variable'; run; But what if you want to execute more than one statement at a time?
Suppose, for example, that you want to assign values conditionally as shown
in the table below. Here, you want not only to assign values to
|
if Code is | and Months is | then Type is |
---|---|---|
1 | 360 | Fixed Mortgage |
1 | not 360 | Fixed Other |
2 | any value | Variable |
One way of assigning these values is to write a series of
IF-THEN and ELSE statements like these:
data finance.newloan; set finance.records(drop=amount rate); length Type $ 14; TotalLoan+payment; if code='1' and months=360 then type='Fixed Mortgage'; else if code='1' then type='Fixed Other'; else type='Variable'; run;
However, you can avoid checking the value of |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.