Previous Page | Next Page

The MPS-Format SAS Data Set

Example 16.4 Using the %MPS2SASD Macro

We illustrate the use of the %MPS2SASD macro in this example, assuming the files example_fix.mps and example_free.mps are in your current SAS working directory.

The MPS2SASD macro function has one required parameter, MPSFILE= 'infilename', which specifies the path and name of the MPS/QPS-format file. With this single parameter, the macro reads the file, converts the records, and saves the conversion to the default MPS-format SAS data set MPSDATA.

Running the following statements converts the fixed-format MPS file shown in Example 16.2 to the MPS-format SAS data set MPSDATA:

%mps2sasd(mpsfile='example_fix.mps');
proc print data=mpsdata;
run;

Output 16.4.1 displays the MPS-format SAS data set MPSDATA.

Output 16.4.1 The MPS-Format SAS Data Set MPSDATA
Obs field1 field2 field3 field4 field5 field6
1 NAME   PROD_MIX .   .
2 ROWS     .   .
3 N PROFIT   .   .
4 L STAMP   .   .
5 L ASSEMB   .   .
6 L FINISH   .   .
7 N CHNROW   .   .
8 N PRICE   .   .
9 COLUMNS     .   .
10   DESK STAMP 3.0 ASSEMB 10
11   DESK FINISH 10.0 PROFIT -95
12   DESK PRICE 175.0   .
13   CHAIR STAMP 1.5 ASSEMB 6
14   CHAIR FINISH 8.0 PROFIT -41
15   CHAIR PRICE 95.0   .
16   CABINET STAMP 2.0 ASSEMB 8
17   CABINET FINISH 8.0 PROFIT -84
18   CABINET PRICE 145.0   .
19   BOOKCSE STAMP 2.0 ASSEMB 7
20   BOOKCSE FINISH 7.0 PROFIT -76
21   BOOKCSE PRICE 130.0 CHNROW 1
22 RHS     .   .
23   TIME STAMP 800.0 ASSEMB 1200
24   TIME FINISH 800.0   .
25 RANGES     .   .
26   T1 ASSEMB 900.0   .
27 BOUNDS     .   .
28 UP BND CHAIR 75.0   .
29 LO BND BOOKCSE 50.0   .
30 ENDATA     .   .

Running the following statement converts the free-format MPS file shown in Example 16.3 to the MPS-format SAS data set MPSDATA:

%mps2sasd(mpsfile='example_free.mps');

The data set is identical to the one shown in Output 16.4.1.

In the following statement, when the free-format MPS file is converted, the length of the variables field2, field3, and field5 in the SAS data set MPSDATA is explicitly set to 10 characters:

%mps2sasd(mpsfile='example_free.mps', maxlen=10, format=free);

If you want to save the converted data to a SAS data set other than the default data set MPSDATA, you can use the parameter OUTDATA= mpsdata. The following statement reads data from the file example_fix.mps and writes the converted data to the data set PRODMIX:

%mps2sasd(mpsfile='example_fix.mps', outdata=PRODMIX);
Previous Page | Next Page | Top of Page