The DATASOURCE Procedure

Renaming Time Series Variables

Sometimes the time series variable names as given by data vendors are not descriptive enough, or you may 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 13.5 and Figure 13.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 rename in the Selecting Time Series Variables – The KEEP and DROP Statements section.

Figure 13.5: Renaming and Labeling 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 5
2 charmkt F___AC: Market Rate Conversion Used in Charlie Test 5



Figure 13.6: Renaming and Labeling 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 5   F___AA: Market Rate Conversion Factor Used in Alpha Test
7 charmkt Num 5   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.