The MPS-Format SAS Data Set

Example 18.4 Using the %MPS2SASD Macro

This example illustrates the use of the %MPS2SASD macro, assuming that 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 18.2 to the MPS-format SAS data set MPSData:

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

Output 18.4.1 displays the MPS-format SAS data set MPSData. Note that the macro creates a variable, _ID_, in addition to the six variables already described. This variable is ignored by the optimization procedures when the input is a data set, but it is used when the input is a data table. For more information about the _ID_ variable, see SAS Optimization: Mathematical Optimization Procedures.

Output 18.4.1: The MPS-Format SAS Data Set MPSData

Obsfield1field2field3field4field5field6_id_
1NAME PROD_MIX. .2
2ROWS  . .3
3NPROFIT . .4
4LSTAMP . .5
5LASSEMB . .6
6LFINISH . .7
7COLUMNS  . .8
8 DESKSTAMP3.0ASSEMB109
9 DESKFINISH10.0PROFIT-9510
10 CHAIRSTAMP1.5ASSEMB611
11 CHAIRFINISH8.0PROFIT-4112
12 CABINETSTAMP2.0ASSEMB813
13 CABINETFINISH8.0PROFIT-8414
14 BOOKCSESTAMP2.0ASSEMB715
15 BOOKCSEFINISH7.0PROFIT-7616
16RHS  . .17
17 TIMESTAMP800.0ASSEMB120018
18 TIMEFINISH800.0 .19
19RANGES  . .20
20 T1ASSEMB900.0 .21
21BOUNDS  . .22
22UPBNDCHAIR75.0 .23
23LOBNDBOOKCSE50.0 .24
24ENDATA  . .25


Running the following statement converts the free-format MPS file shown in Example 18.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 18.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);

Last updated: August 11, 2020