The DATASOURCE Procedure

Renaming Time Series Variables

(View the complete code for this example.)

Sometimes the time series variable names as given by data vendors are not descriptive enough, or you might prefer a different naming convention. In such cases, you can use the RENAME statement to assign more meaningful names to time series variables. You can also use LABEL statements to associate descriptive labels with your series variables.

For example, the series names for market rate conversion factor (F___AA) and market rate conversion factor (F___AC) used by IMF can be given more descriptive names and labels by the following statements and are shown in Figure 12.5 and Figure 12.6.

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';
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;

The RENAME statement allows input names to be quoted strings. If the name of a series in the input file contains blanks or special characters that are not in valid SAS name syntax, use the SAS option VALIDVARNAME=ANY or put the series name in quotes to rename it. See the FAME example using the RENAME statement in the section Selecting Time Series Variables: The KEEP and DROP Statements.

Figure 12.5: Renaming and Labeling Variables

Printout of OUTCONT= Showing New NAMEs and LABELs

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


Figure 12.6: Renaming and Labeling 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
6alphmktNum5 F___AA: Market Rate Conversion Factor Used in Alpha Test
7charmktNum5 F___AC: Market Rate Conversion Used in Charlie Test


Notice that even though you changed the names of F___AA and F___AC to alphmkt and charmkt, respectively, you still use their old names in the KEEP and LABEL statements because renaming takes place at the output stage.

Last updated: August 25, 2017