Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-21-2019 05:31 PM
(1233 views)

I'm trying to optimize a football team in PROC OPTMODEL. I've successfully created the code which produces the report, but I want to save my decision variables outcome into a dataset. I read the following SAS documentation which suggests to use 'create data' statement, but I'm very new to PROC OPTMODEL and I'm not able to get the expected output.

The code is as follows:

```
proc optmodel;
set <string> PLAYERS;
set <string> DEF = {"Alonso", "Azpilicueta", "Cahill", "Christensen", "David Luiz", "Emerson", "Moses", "Rudiger", "Zappacosta"};
set <string> FWD = {"Abraham","Giroud","Morata"};
set <string> GKP = {"Caballero","Courtois","Kepa"};
set <string> MID = {"Ampadu", "Bakayoko", "Barkley", "Drinkwater", "Fabregas", "Hazard", "Hudson-Odoi", "Jorginho", "Kante", "Kovacic", "Loftus-Cheek", "Pedro", "Willian"};
set <string> WeekMatch;
number NewPoints{PLAYERS};
number threshold{WeekMatch};
read data WORK.PLAYERS into PLAYERS = [Name] NewPoints;
read data WORK.THRESH into WeekMatch = [week] threshold;
var x{PLAYERS, WeekMatch} binary;
var win{WeekMatch} binary;
Maximize numberofwin = sum {i in WeekMatch} win[i];
/*constraint on maximum number of times a player can play*/
con ConsecutivePlay {i in PLAYERS}: sum {j in WeekMatch} x[i,j] <= 25;
/*opponent threshold constraint*/
con WinTotal {j in WeekMatch} : sum {i in PLAYERS} x[i,j] * NewPoints[i] >= threshold[j] * win[j];
/*position constraints*/
con weekDEF {j in WeekMatch} : sum {i in DEF} x[i,j] = 4;
con weekFWD {j in WeekMatch} : sum {i in FWD} x[i,j] = 1;
con weekGKP {j in WeekMatch} : sum {i in GKP} x[i,j] = 1;
con weekMID {j in WeekMatch} : sum {i in MID} x[i,j] = 5;
solve with milp;
print numberofwin x win;
create data numberofwin from count=numberofwin;
quit;
```

The supporting data is attached.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The following statement will create a data set with one observation for each assignment that appears in the solution:

`create data solution from [i j]={i in PLAYERS, j in WeekMatch: x[i,j].sol > 0.5};`

If you prefer the column names to be player and week, you can do this instead:

```
create data solution from [player=i week=j]={i in PLAYERS, j in WeekMatch: x[i,j].sol > 0.5};
```

If you prefer week to appear as the first column, you can do this:

```
create data solution from [week=j player=i]={j in WeekMatch, i in PLAYERS: x[i,j].sol > 0.5};
```

If you want a two-dimensional table of 0 and 1, you can do this:

`create data solution from [player=i]=PLAYERS {j in WeekMatch} <col(j)=x[i,j].sol>;`

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The following statement will create a data set with one observation for each assignment that appears in the solution:

`create data solution from [i j]={i in PLAYERS, j in WeekMatch: x[i,j].sol > 0.5};`

If you prefer the column names to be player and week, you can do this instead:

```
create data solution from [player=i week=j]={i in PLAYERS, j in WeekMatch: x[i,j].sol > 0.5};
```

If you prefer week to appear as the first column, you can do this:

```
create data solution from [week=j player=i]={j in WeekMatch, i in PLAYERS: x[i,j].sol > 0.5};
```

If you want a two-dimensional table of 0 and 1, you can do this:

`create data solution from [player=i]=PLAYERS {j in WeekMatch} <col(j)=x[i,j].sol>;`

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@RobPratt Thank you so much, this works very well. I was particularly interested in the last solution you mentioned.

But, this only give me the dataset for x, can you please suggest how to store 'win'.

Thank you again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
create data windata from [week] win;
```

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.