SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Variables
Executing Multiple Statements Conditionally


During the first iteration of the DATA step, the first observation is read from Finance.Records. The variables Amount and Rate are dropped.

     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


The LENGTH statement is a compile-time statement and is therefore not executed. (Remember to change LENGTH statements to accommodate new variable values such as Fixed Mortgage.)

     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;

Next, the value of Payment is added to TotalLoan.

     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



back||next


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

Terms of Use & Legal Information | Privacy Statement