SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Variables
Specifying Lengths for Variables


Previously, you added IF-THEN and ELSE statements to a DATA step in order to create a variable for type of loan -- fixed rate or variable rate. Values for Type were assigned conditionally, based on the value for Code.

     data finance.newloan;
        set finance.records(drop=amount rate);
        TotalLoan+payment;
        if code='1' then Type='Fixed';
        else Type='Variable';
     run;

But look what happens when you submit this program.

During compilation, when creating a new variable, SAS software allocates as many bytes of storage space as there are characters in that variable's first value. In this particular case, the first value for the variable Type is Fixed, which is only five characters long. As execution continues and other values are assigned, they are all truncated to five characters. The value Variable is thus written to the data set as Varia.


SAS Data Set Finance.Newloan
Account Months Payment Code TotalLoan Type
101-1092 60 467.43 1 467.43 Fixed
101-1731 360 958.57 2 1426.00 Varia
101-1289 36 325.02 2 1751.02 Varia
101-3144 12 308.52 1 2059.54 Fixed



back||next


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

Terms of Use & Legal Information | Privacy Statement