DATASOURCE Procedure

Example 12.1 BEA National Income and Product Accounts

(View the complete code for this example.)

In this example, exports and imports of goods and services are extracted to demonstrate how to work with a National Income and Product Accounts (NIPA) file.

From the "Statistical Tables" published by the United States Department of Commerce, Bureau of Economic Analysis, the relation of foreign transactions in the Balance of Payments Accounts (BPA) are given in the fifth table (TABNUM=’05’) of the "Foreign Transactions" section (PARTNO=’4’). Moreover, the first line in the table gives BPAs, while the eighth gives exports of goods and services. The series names __00100 and __00800 are constructed by two underscores followed by three digits as the line numbers, and then two digits as the column numbers.

The following statements put this information together to extract quarterly BPAs and exports from a BEANIPA type file:

/*- assign fileref to the external file to be processed --------*/

filename ascifile "%sysget(DATASRC_DATA)beanipa.data" recfm=v lrecl=108;

title1 'Relation of Foreign Transactions to Balance of Payment Accounts';
title2 'Range from 1984 to 1989';

title3 'Annual';
proc datasource filetype=beanipa infile=ascifile
                interval=year
                outselect=off
                outkey=byfor4;

   range from 1984 to 1989;
   keep __00100 __00800;

   label __00100='Balance of Payment Accounts';
   label __00800='Exports of Goods and Services';

   rename __00100=BPAs __00800=exports;
run;

proc print data=byfor4;
run;
 /*- assign fileref to the external file to be processed --------*/

filename ascifile "%sysget(DATASRC_DATA)beanipa.data" recfm=v lrecl=108;

title1 'Relation of Foreign Transactions to Balance of Payment Accounts';
title2 'Range from 1984 to 1989';

title3 'Annual';
proc datasource filetype=beanipa infile=ascifile
                interval=year
                outselect=off
                outkey=byfor4
                out=foreign4;

   range from 1984 to 1989;
   keep __00100 __00800;

   label __00100='Balance of Payment Accounts';
   label __00800='Exports of Goods and Services';

   rename __00100=BPAs __00800=exports;

run;

proc contents data=foreign4;
run;
proc print data=foreign4;
run;

The results are shown in Output 12.1.1, Output 12.1.2, and Output 12.1.3.

Output 12.1.1: Listing of OUTBY=byfor4 of the BEANIPA Data

Relation of Foreign Transactions to Balance of Payment Accounts
Range from 1984 to 1989
Annual

ObsPARTNOTABNUMST_DATEEND_DATENTIMENOBSNINRANGENSERIESNSELECT
110719291989610620
211419291989610610
311519291989610610
4120196719892323621
512319291989610620
620419291989610610
720519291989610620
830519291989610610
931419521989380620
1031519521989380670
1131619521989380610
12405194619894444611
1350719291989610610
1450919291989610610
1560419291989610630
1660519291948200020
1760719291948200010
1860819291989610630
1960919481989420610
2061019291948200010
2161419291948200010
2261919291948200010
2362019291989610620
2462219291989610620
2562319481989420610
2662419481989420610
2770919291989610610
2871019291989610620
2971319591989310610


Output 12.1.2: CONTENTS of OUT=foreign4 of the BEANIPA Data

Relation of Foreign Transactions to Balance of Payment Accounts
Range from 1984 to 1989
Annual

The CONTENTS Procedure

Alphabetic List of Variables and Attributes
#VariableTypeLenFormatLabel
3DATENum4YEAR4.Date of Observation
1PARTNOChar1 Part Number of Publication, IntegerPortion of the Table Number, 1-9
2TABNUMChar2 Table Number Within Part, DecimalPortion of the Table Number, 1-24
4exportsNum5 Exports of Goods and Services


Output 12.1.3: Listing of OUT=foreign4 of the BEANIPA Data

Relation of Foreign Transactions to Balance of Payment Accounts
Range from 1984 to 1989
Annual

ObsPARTNOTABNUMDATEexports
1120198444
2120198553
3120198646
4120198740
5120198848
6120198947
740519843835
840519853709
940519863965
1040519874496
1140519885520
1240519896262


This example illustrates the following features:

  • You need to know the series variables names used by a particular vendor in order to construct the KEEP statement.

  • You need to know the BY-variable names and their values for the required cross sections.

  • You can use RENAME and LABEL statements to associate more meaningful names and labels with your selected series variables.

Last updated: June 19, 2025