SAS/OR

This page summarizes how to use SAS/OR for policy modeling.

SAS/OR BASICS

- What is needed to use the LP procedure in SAS/OR? Twofold. The first is to create a data set that contains the model including the objective function and constraints. Second is to invoke PROC LP to solve and analyze the problem by using a variety of options of the PROC LP procedure.
- Thre are two different ways to create a data set for PROC LP. One is called "Dense Format," the default format, which looks like the list of a objective function and constraint formulas. The other is the "Sparse Format" which is more flexible in that it enables us to omit the zero coefficients; only those variables with non-zero coefficient need to be listed in the DATA step. That is, the sparse format is highly preferred to deal with models with a number of variables and lots of zero coefficients in constraints.
- The Dense Format requires _ID_ (for the names of objective functions and constraints), _TYPE_ (for relation operator, such as MAX, MIN, LE, and GE), _RHS_ (for right hand side values).
- The Sparse Format needs _TYPE_, _ROW_ (for the names of the objective functions and constraints), _COL_ (for variable names), and _COEF_ (for coefficients in the objective function and constraints). In order to use a sparse formatted data set, we need to specify the "SPARSEDATA" option in the PROC LP procedure (PROC LP DATA=mixing SPARSEDATA).

INDENSE FORMAT

DATA mixing;

INPUT _ID_ $ x y z _TYPE_ $ _RHS_;

DATALINES;

object 5 3 2 MAX .

C1 4 1 0 LE 15

C2 2 0 4 LE 20;

RUN;

PROC LP; RUN;

INPUT _ID_ $ x y z _TYPE_ $ _RHS_;

DATALINES;

object 5 3 2 MAX .

C1 4 1 0 LE 15

C2 2 0 4 LE 20;

RUN;

PROC LP; RUN;

- _ID_ denotes the names of objective function and constraints.
- _TYPE_ indicates the relation operators used in the objective function and constraints. MAX, MIN, LE, GE, EQ, SOSLE, SOSEQ, UNRSTRICT, UPPERBD, LOWERBD, BASIC, PRICESEN, FREE, INTEGER, and BINARY are available.
- For INTEGER and BINARY, the coefficient of each variable needs to be ordered and its RHS should be "." (e.g., C6 1 2 3 4 5 BINARY .) INTEGER must be upper and lower bounded. BINARY "identifies variables that are constrained to be either 0 or 1. This is equivalent to specifying that the variable is an integer variable and has a lower bound of 0 and an upper bound of 1."
- _RHS_ indicates the right-hand side values
- "PROC LP;" invokes LP procedure to solve the problem based on the data set provided. In the example, the data set will be "mixing," current data set modified recently, since no data set is specified in the PROC LP statement.

SPARSE FORMAT

DATA mixing;

FORMAT _TYPE_ $4. _ROW_ $7. _COL_ $5.;

INPUT _TYPE_ $ _ROW_ $ _COL_ $ _COEF_;

DATALINES;

MAX Object . .

. Object x 5

. Object y 3

. Object z 2

LE C1 . .

. C1 x 4

. C1 y 1

. C1 _RHS_ 15

LE C2 . .

. C2 x 2

. C2 z 4

. C2 _RHS_ 20;

RUN;

PROC LP DATA=mixing SPARSEDATA DUALOUT=mix_dual RANGE x y z;

RUN;

FORMAT _TYPE_ $4. _ROW_ $7. _COL_ $5.;

INPUT _TYPE_ $ _ROW_ $ _COL_ $ _COEF_;

DATALINES;

MAX Object . .

. Object x 5

. Object y 3

. Object z 2

LE C1 . .

. C1 x 4

. C1 y 1

. C1 _RHS_ 15

LE C2 . .

. C2 x 2

. C2 z 4

. C2 _RHS_ 20;

RUN;

PROC LP DATA=mixing SPARSEDATA DUALOUT=mix_dual RANGE x y z;

RUN;

- The DATA statement produces exactly the same data set as one by the dense format. The order of observations is not important:one of typical SAS conventions.
- _TYPE_ contains keywords, such as MAX, MIN, LE, and GE. _ROW_ contains the names of the objective function and constraints in the model. _COL_ contains variable names including _RHS_. _COEF_ contains the coefficients of the variables. Notice the difference in the location of _RHS_ between the two formats.
- The sparse format requires us to use "SPARSEDATA" option in the PROC LP procedure. DUALOUT option needs to get a new data set containing dual value analysis.

PROC LP

PROC LP PRIMALOUT=mix_prim TABLEAUOUT=mix_tabl RANGEPRICE;

PIVOT;

COEF coeff;

RHS rhs;

RANGE x y z;

RUN;

PROC PRINT DATA=mix_prim; RUN; /*to print primal solution*/

RUN;

PIVOT;

COEF coeff;

RHS rhs;

RANGE x y z;

RUN;

PROC PRINT DATA=mix_prim; RUN; /*to print primal solution*/

RUN;

- Major data set options are ACTIVEIN="data set", ACTIVEOUT="data set", DATA="data set", DUALOUT="data set" (to save the current dual solution-shadow prices), PRIMALIN="data set", PRIMALOUT="data set" (to save the current primal solution), SPARSEDATA, and TABLEAUOUT="data set" (to save the final tableau).
- Main print control options are (NO)FLOW (to print a journal of pivot information), (NO)PARAPRINT (to print the solution at each pivot), (NO)TABLEAUPRINT (to print the final tableau), and PRINTFREQ=i (to print a line in the ITERATION LOG at each ith iteration).
- Among sensitivity/parametric/ranging control options are (NO)RANGEPRICE (to perform a range analysis on the price coefficients) and (NO)RANGERHS (to perform a range analysis on the right-hand-side vector).
- Format Statement: COEF (Sparse format), COL (Sparse format), RANGE, RHS, RHSSEN, ROW, TYPE, VAR (dense format)
- Interactive Statements: IPIVOT, PIVOT (to execute one simplex pivot and pause), PRINT, QUIT, RESET, SHOW, RUN
- Each of COEF, COL, TYPE, ROW statements can be omitted if _COEF_, _COL_, _ROW_, and _TYPE_ are used in a data set.

PROC CPM

DATA software;

INPUT id $char10. days 3.0 act $char2. sc1 $char2. sc2 $char2.

DATALINES;

Analysis 03 A B

Design 04 B C D

Coding 05 C D

Test 03 D E

Producing 03 E F

Packing 06 F

; RUN;

INPUT id $char10. days 3.0 act $char2. sc1 $char2. sc2 $char2.

DATALINES;

Analysis 03 A B

Design 04 B C D

Coding 05 C D

Test 03 D E

Producing 03 E F

Packing 06 F

; RUN;

PROC CPM DATA=software OUT=soft_out INTERVAL=day DATE='01dec2001'd;

ID id;

ACTIVITY act;

DURATION days;

SUCCESSOR sc1 sc2;

RUN;

ID id;

ACTIVITY act;

DURATION days;

SUCCESSOR sc1 sc2;

RUN;

PROC PM

REFERENCES

- SAS Institute Inc. 1991. SAS/OR User's Guide (Version 6). 1st ed. Gary, NC. (In particular, Chapter 3 and 7)