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 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. Output is shown in Figure 12.7 and Figure 12.8.

filename ifsfile "%sysget(DATASRC_DATA)imfifs1.dat" RECFM=F LRECL=88;

proc datasource filetype=imfifsp infile=ifsfile
                interval=month
                out=market outcont=mrktvars;
   where country in ('112','146','158') and partner=' ';
   keep  f___aa f___ac;
   range from '01jun85'd to '01feb86'd;
   rename  f___aa=alphmkt  f___ac=charmkt;
   label   f___aa='F___AA: Market Rate Conversion Factor Used in Alpha Test'
           f___ac='F___AC: Market Rate Conversion Used in Charlie Test';
   length _numeric_ 4;
   length f___aa 6;
run;

title1 'Printout of OUTCONT= Showing New NAMEs and LABELs';
proc print data=mrktvars ;
   var  name label length;
run;

title1 'Contents of OUT= Showing New NAMEs and LABELs';
proc contents data=market;
run;

Figure 12.7: Changing the Lengths of Numeric Variables

Printout of OUTCONT= Showing New NAMEs and LABELs

Obs NAME LABEL LENGTH
1 alphmkt F___AA: Market Rate Conversion Factor Used in Alpha Test 6
2 charmkt F___AC: Market Rate Conversion Used in Charlie Test 4



Figure 12.8: Changing the Lengths of Numeric Variables

Alphabetic List of Variables and Attributes
# Variable Type Len Format Label
1 COUNTRY Char 3   COUNTRY CODE
2 CSC Char 1   CONTROL SOURCE CODE
5 DATE Num 4 MONYY7. Date of Observation
3 PARTNER Char 3   PARTNER COUNTRY CODE
4 VERSION Char 1   VERSION CODE
6 alphmkt Num 6   F___AA: Market Rate Conversion Factor Used in Alpha Test
7 charmkt Num 4   F___AC: Market Rate Conversion Used in Charlie Test



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