DATASOURCE Procedure

Changing the Lengths of Numeric Variables

(View the complete code for this example.)

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 might 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 7 and Figure 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 7: Changing the Lengths of Numeric Variables

Printout of OUTCONT= Showing New NAMEs and LABELs

ObsNAMELABELLENGTH
1alphmktF___AA: Market Rate Conversion Factor Used in Alpha Test6
2charmktF___AC: Market Rate Conversion Used in Charlie Test4


Figure 8: Changing the Lengths of Numeric Variables

Alphabetic List of Variables and Attributes
#VariableTypeLenFormatLabel
1COUNTRYChar3 COUNTRY CODE
2CSCChar1 CONTROL SOURCE CODE
5DATENum4MONYY7.Date of Observation
3PARTNERChar3 PARTNER COUNTRY CODE
4VERSIONChar1 VERSION CODE
6alphmktNum6 F___AA: Market Rate Conversion Factor Used in Alpha Test
7charmktNum4 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.

Last updated: June 19, 2025