Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
The DATASOURCE Procedure

Changing the Lengths of Numeric Variables

The length attribute indicates the number of bytes the SAS System uses for storing the values of variables in output data sets. Therefore, the shorter the variable lengths, the more efficient the disk-space usage. However, there is a trade-off. The lengths of numeric variables are closely tied to their precision, and reducing their lengths arbitrarily can cause precision loss.

The DATASOURCE procedure uses default lengths for series variables appropriate to each file type. For example, the default lengths for numeric variables are 5 for IMFIFSP type files. In some cases, however, you may want to assign different lengths. Assigning lengths less than the defaults reduces memory and disk-space usage at the expense of reduced precision. Specifying lengths longer than the defaults increases the precision but causes the DATASOURCE procedure to use more memory and disk space. The following statements define a default length of 4 for all numeric variables in the IFSFILE and then assign a length of 6 to the exchange rate index:

   filename ifsfile 'host-specific-file-name' <host-options>;
   proc datasource filetype=imfifsp infile=ifsfile interval=month
                   out=exchange outcont=exchvars;
      where country in ('112','146','158') and partner='   ';
      keep  f_x_am f_x_ah;
      range from '01jun87'd to '01feb88'd;
      rename  f_x_ah=exrindex  f_x_am=effexr;
      label   f_x_ah='F_X_AH: Exchange Rate Index 1985=100'
              f_x_am='F_X_AM: Effective Exchange Rate(MERM)';
      length _numeric_ 4; length f_x_ah 6;
   run;
   
   title1 'Printout of OUTCONT= Showing LENGTH Variable';
   proc print data=exchvars noobs;
      var  name label length;
   run;
   
   title1 'Contents of the OUT= Data Set Showing LENGTHs';
   proc contents data=exchange;
   run;

Printout of OUTCONT= Showing LENGTH Variable

name label length
EFFEXR F_X_AM: Effective Exchange Rate(MERM) 4
EXRINDEX F_X_AH: Exchange Rate Index 1985=100 6

Contents of the OUT= Data Set Showing LENGTHs

The CONTENTS Procedure

Data Set Name: WORK.EXCHANGE Observations: 27
Member Type: DATA Variables: 7
Engine: V7 Indexes: 0
Created: 0:28 Monday, June 1, 1998 Observation Length: 24
Last Modified: 0:28 Monday, June 1, 1998 Deleted Observations: 0
Protection:   Compressed: NO
Data Set Type:   Sorted: NO
Label:      

-----Engine/Host Dependent Information-----
Data Set Page Size: 8192
Number of Data Set Pages: 1
First Data Page: 1
Max Obs per Page: 338
Obs in First Data Page: 27
Number of Data Set Repairs: 0
File Name: /tmp/SAS_workAFBC000027F8/exchange.sas7bdat
Release Created: 7.00.00P
Host Created: HP-UX
Inode Number: 14450
Access Permission: rw-r--r--
Owner Name: sasknh
File Size (bytes): 16384

-----Alphabetic List of Variables and Attributes-----
# Variable Type Len Pos Format Label
3 country Char 3 8   COUNTRY CODE
4 csc Char 1 11   CONTROL SOURCE CODE
7 date Num 4 4 MONYY7. Date of Observation
2 effexr Num 4 0   F_X_AM: Effective Exchange Rate(MERM)
1 exrindex Num 6 16   F_X_AH: Exchange Rate Index 1985=100
5 partner Char 3 12   PARTNER COUNTRY CODE
6 version Char 1 15   VERSION CODE

Figure 10.7: Changing the Lengths of Numeric Variables

The default lengths of the character variables are set to the minimum number of characters that can hold the longest possible value.

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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