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
| Obs | field1 | field2 | field3 | field4 | field5 | field6 | _id_ |
|---|---|---|---|---|---|---|---|
| 1 | NAME | PROD_MIX | . | . | 2 | ||
| 2 | ROWS | . | . | 3 | |||
| 3 | N | PROFIT | . | . | 4 | ||
| 4 | L | STAMP | . | . | 5 | ||
| 5 | L | ASSEMB | . | . | 6 | ||
| 6 | L | FINISH | . | . | 7 | ||
| 7 | COLUMNS | . | . | 8 | |||
| 8 | DESK | STAMP | 3.0 | ASSEMB | 10 | 9 | |
| 9 | DESK | FINISH | 10.0 | PROFIT | -95 | 10 | |
| 10 | CHAIR | STAMP | 1.5 | ASSEMB | 6 | 11 | |
| 11 | CHAIR | FINISH | 8.0 | PROFIT | -41 | 12 | |
| 12 | CABINET | STAMP | 2.0 | ASSEMB | 8 | 13 | |
| 13 | CABINET | FINISH | 8.0 | PROFIT | -84 | 14 | |
| 14 | BOOKCSE | STAMP | 2.0 | ASSEMB | 7 | 15 | |
| 15 | BOOKCSE | FINISH | 7.0 | PROFIT | -76 | 16 | |
| 16 | RHS | . | . | 17 | |||
| 17 | TIME | STAMP | 800.0 | ASSEMB | 1200 | 18 | |
| 18 | TIME | FINISH | 800.0 | . | 19 | ||
| 19 | RANGES | . | . | 20 | |||
| 20 | T1 | ASSEMB | 900.0 | . | 21 | ||
| 21 | BOUNDS | . | . | 22 | |||
| 22 | UP | BND | CHAIR | 75.0 | . | 23 | |
| 23 | LO | BND | BOOKCSE | 50.0 | . | 24 | |
| 24 | ENDATA | . | . | 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);