| Creating Variables |
| Executing Multiple Statements
Conditionally |
The IF-THEN statement determines if the value of Code is 1.
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;
|
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 |
Because Code does equal 1 for this observation, the DO statement is executed.
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 statement in the DO group determines if Months is equal to 360.
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;
|
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 |
![]() ![]() |
|
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.