| Creating Variables |
| Executing Multiple Statements
Conditionally |
Because the IF statement is false, the ELSE statement is executed and the value Fixed Other is assigned to Type.
data finance.newloan;
set finance.records(drop=amount rate);
length Type $ 14;
TotalLoan+payment;
if code='1' then
do;
if months=360 then
type='Fixed Mortgage';
else type='Fixed Other';
end;
else type='Variable';
run;
The DO group ends. Because the first IF-THEN statement is true, the corresponding ELSE statement does not execute.
data finance.newloan;
set finance.records(drop=amount rate);
length Type $ 14;
TotalLoan+payment;
if code='1' then
do;
if months=360 then
type='Fixed Mortgage';
else type='Fixed Other';
end;
else type='Variable';
run;
The IF-THEN and ELSE statements evaluate each observation in the data set in the same manner. |
SAS Data Set Finance.Records
| Account | Amount | Rate | Months | Payment | Code |
| 101-1092 | 22000 | 0.1000 | 60 | 467.43 | 1 |
| 101-1731 | 114000 | 0.0950 | 360 | 958.57 | 2 |
| 101-1289 | 10000 | 0.1050 | 36 | 325.02 | 2 |
| 101-3144 | 3500 | 0.1050 | 12 | 308.52 | 1 |
SAS Data Set Finance.Newloan
| Account | Months | Payment | Code | TotalLoan | Type |
| 101-1092 | 60 | 467.43 | 1 | 467.43 | Fixed Other |
| 101-1731 | 360 | 958.57 | 2 | 1426.01 | Variable |
| 101-1289 | 36 | 325.02 | 2 | 1751.03 | Variable |
| 101-3144 | 12 | 308.52 | 1 | 2059.55 | Fixed Other |
| 103-1135 | 24 | 403.47 | 1 | 2463.02 | Fixed Other |
| 103-1994 | 60 | 393.07 | 2 | 2856.10 | Variable |
| 103-2335 | 48 | 128.02 | 1 | 2984.11 | Fixed Other |
| 103-3864 | 360 | 735.75 | 1 | 3719.86 | Fixed Mortgage |
| 103-3891 | 360 | 257.75 | 2 | 3977.61 | Variable |
![]() ![]() |
|
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.