The DATASOURCE Procedure

Example 12.4 DRI/McGraw-Hill Format CITIBASE Files

(View the complete code for this example.)

Output 12.4.1 and Output 12.4.2 illustrate how to extract weekly series from a sample CITIBASE file. They also demonstrate how the OUTSELECT= option affects the contents of the auxiliary data sets.

The weekly series contained in the sample data file CITIDEMO are listed by the following statements:

options yearcutoff=1920;

filename datafile "%sysget(DATASRC_DATA)citidem.dat" RECFM=D LRECL=80;

proc datasource filetype=citibase interval=week
                outall=citiall outby=citikey;
run;

title1 'Summary Information on Weekly Data for CITIDEMO File';
proc print data=citikey;
run;

title1 'Weekly Series Available in CITIDEMO File';
proc print data=citiall( drop=label );
run;

Output 12.4.1: Listing of the OUTBY= CITIKEY Data Set

Summary Information on Weekly Data for CITIDEMO File

ObsST_DATEEND_DATENTIMENOBSNSERIESNSELECT
1Sun, 29 Dec 1985Sun, 3 Mar 199127127166


Output 12.4.2: Listing of the OUTALL= CITIALL Data Set

Weekly Series Available in CITIDEMO File

ObsNAMESELECTEDTYPELENGTHVARNUMBLKNUMFORMATFORMATLFORMATDST_DATEEND_DATENTIMENOBSCODEATTRIBUTNDEC
1FF142B115.36 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271FF142B12
2WSPCA115.37 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271WSPCA12
3WSPUA115.38 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271WSPUA12
4WSPIA115.39 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271WSPIA12
5WSPGLT115.40 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271WSPGLT12
6FCPOIL115.41 00Sun, 29 Dec 1985Sun, 3 Mar 1991271271FCPOIL14


Note the following from Output 12.4.2:

  • The OUTALL= data set reports the time ranges of variables.

  • There are six observations in the OUTALL= data set, the same number as reported by NSERIES and NSELECT variables in the OUTBY= data set.

  • The VARNUM variable contains all MISSING values, since no OUT= data set is created.

Output 12.4.3 and Output 12.4.4 demonstrate how the OUTSELECT= option affects the contents of the OUTBY= and OUTALL= data sets when a KEEP statement is present. First, set the OUTSELECT= option to OFF.

filename citidemo "%sysget(DATASRC_DATA)citidem.dat" RECFM=D LRECL=80;

proc datasource filetype=citibase infile=citidemo interval=week
                outall=alloff outby=keyoff outselect=off;
   keep WSP:;
run;

title1 'Summary Information on Weekly Data for CITIDEMO File';
proc print data=keyoff;
run;

title1 'Weekly Series Available in CITIDEMO File';
proc print data=alloff( keep=name kept selected st_date
                             end_date ntime nobs );
run;

Output 12.4.3: Listing of the OUTBY= Data Set with OUTSELECT=OFF

Summary Information on Weekly Data for CITIDEMO File

ObsST_DATEEND_DATENTIMENOBSNSERIESNSELECT
1Sun, 29 Dec 1985Sun, 3 Mar 199127127164


Output 12.4.4: Listing of the OUTALL= Data Set with OUTSELECT=OFF

Weekly Series Available in CITIDEMO File

ObsNAMEKEPTSELECTEDST_DATEEND_DATENTIMENOBS
1FF142B00Sun, 29 Dec 1985Sun, 3 Mar 1991271271
2WSPCA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
3WSPUA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
4WSPIA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
5WSPGLT11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
6FCPOIL00Sun, 29 Dec 1985Sun, 3 Mar 1991271271


Specifying OUTSELECT=ON gives the results shown in Output 12.4.5 and Output 12.4.6.

filename citidemo "%sysget(DATASRC_DATA)citidem.dat" RECFM=D LRECL=80;
proc datasource filetype=citibase infile=citidemo
                interval=week
                outall=allon outby=keyon outselect=on;
   keep WSP:;
run;

title1 'Summary Information on Weekly Data for CITIDEMO File';
proc print data=keyon;
run;

title1 'Weekly Series Available in CITIDEMO File';
proc print data=allon( keep=name kept selected st_date
                            end_date ntime nobs );
run;

Output 12.4.5: Listing of the OUTBY= Data Set with OUTSELECT=ON

Summary Information on Weekly Data for CITIDEMO File

ObsST_DATEEND_DATENTIMENOBSNSERIESNSELECT
1Sun, 29 Dec 1985Sun, 3 Mar 199127127164


Output 12.4.6: Listing of the OUTALL= Data Set with OUTSELECT=ON

Weekly Series Available in CITIDEMO File

ObsNAMEKEPTSELECTEDST_DATEEND_DATENTIMENOBS
1WSPCA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
2WSPUA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
3WSPIA11Sun, 29 Dec 1985Sun, 3 Mar 1991271271
4WSPGLT11Sun, 29 Dec 1985Sun, 3 Mar 1991271271


Comparison of Output 12.4.4 and Output 12.4.6 reveals the following:

  • The OUTALL= data set contains six (NSERIES) observations when OUTSELECT=OFF, and four (NSELECT) observations when OUTSELECT=ON.

  • The observations in OUTALL=ALLON are those for which SELECTED=1 in OUTALL=ALLOFF.

  • The time ranges in the OUTBY= data set are computed over all the variables (selected or not) for OUTSELECT=OFF, but only computed over the selected variables for OUTSELECT=ON. This corresponds to computing time ranges over all the series reported in the OUTALL= data set.

  • The variable NTIME is the number of time periods between ST_DATE and END_DATE, while NOBS is the number of observations the OUT= data set is to contain. Thus, NTIME is different depending on whether the OUTSELECT= option is set to ON or OFF, while NOBS stays the same.

The KEEP statement in the last two examples illustrates the use of an additional variable, KEPT, in the OUTALL= data sets of Output 12.4.4 and Output 12.4.6. KEPT, which reports the outcome of the KEEP statement, is only added to the OUTALL= data set when there is KEEP statement.

Adding the RANGE statement to the last example generates the data sets in Output 12.4.7 and Output 12.4.8:

filename citidemo "%sysget(DATASRC_DATA)citidem.dat" RECFM=D LRECL=80;
proc datasource filetype=citibase infile=citidemo interval=week
                outby=keyrange out=citiout outselect=on;
   keep WSP:;
   range from '01dec1990'd;
run;

title1 'Summary Information on Weekly Data for CITIDEMO File';
proc print data=keyrange;
run;

title1 'Weekly Data in CITIDEMO File';
proc print data=citiout;
run;

Output 12.4.7: Listing of the OUTBY=KEYRANGE Data Set for FILETYPE=CITIBASE

Summary Information on Weekly Data for CITIDEMO File

ObsST_DATEEND_DATENTIMENOBSNINRANGENSERIESNSELECT
1Sun, 29 Dec 1985Sun, 3 Mar 19912712711564


Output 12.4.8: Printout of the OUT=CITIOUT Data Set for FILETYPE=CITIBASE

Weekly Data in CITIDEMO File

ObsDATEWSPCAWSPUAWSPIAWSPGLT
1Sun, 25 Nov 19909.770009.660009.870008.62000
2Sun, 2 Dec 19909.750009.640009.850008.47000
3Sun, 9 Dec 19909.590009.480009.690008.22000
4Sun, 16 Dec 19909.620009.510009.720008.35000
5Sun, 23 Dec 19909.700009.600009.800008.48000
6Sun, 30 Dec 19909.640009.530009.750008.31000
7Sun, 6 Jan 19919.700009.590009.810008.62000
8Sun, 13 Jan 19919.800009.700009.890008.58000
9Sun, 20 Jan 19919.660009.570009.750008.36000
10Sun, 27 Jan 19919.650009.560009.740008.38000
11Sun, 3 Feb 19919.520009.430009.610008.16000
12Sun, 10 Feb 19919.380009.290009.480008.14000
13Sun, 17 Feb 19919.380009.290009.480008.21000
14Sun, 24 Feb 19919.610009.530009.680008.50000
15Sun, 3 Mar 19919.610009.530009.680008.50000


The OUTBY= data set in this last example contains an additional variable NINRANGE. This variable is added since there is a RANGE statement. Its value, 15, is the number of observations in the OUT= data set. In this case, NOBS gives the number of observations the OUT= data set would contain if there were not a RANGE statement.

Last updated: December 20, 2021