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

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

Posted 01-28-2015 10:08 AM
(6592 views)

Hello my name is Kendall. I am trying to teach myself how to use SAS studio. I have little knowledge on it but have learned a lot in the past couple of days. My ultimate goal is to become efficient in learning how to use the program and learn coding. I would also like to build an optimization model for my fantasy basketball team. Where i have to pick 8 players, one in each position of PG,SG,SF,PF,C G, F and Util…. The G can be either PG or SG. The F can be either SF or PF and the UTIL can be any one of the original 5 listed. I was wondering if you guys would be able to help me and teach me at the same time. I have attached the data i use and created in excel just to give you an idea of what i will be working with.

There are also certain criteria that needs to be meet with this optimal lineup. The players combined can not exceed $50,000 price tag. I would like to use USG and DvP and Projections columns to choose the top players. I would actually like to use a lot more but i can implement that later once i learn to develop it on my own. If you guys would be able to assist me i would greatly appreciate it.

13 REPLIES 13

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

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

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

Okay, I will try to nutshell this:

To solve this kind of problem, the best way (also the official way) is Proc OPTModel, which is part of SAS OR, is an expert and his code in the referred thread is not difficult to follow. I am not sure about your SAS studio, if it is the element that goes with EBI system for your organization, you need to check; if it is the free University edition, you are out of luck.

Another way to tackle it requires sophisticated SAS programming skills, and so far it can't compete PROC OPTMODEL on both performance and reliability. but you said you are a noob?

My suggestion will be trying to find a SAS box that has SAS OR.

Good luck,

Haikuo

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

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

For Draft Kings, the model would look something like this...

I am leaving out some details about how the data is pulled in from Excel (my Excel projection sheet is probably different than yours). The basic model is mostly here. The only rule I left out is that players must be selected from two different teams. But, in my experience, this hardly ever happens in practice.

Good luck - if you figure out how to beat Draft Kings - please let me know!

set<str> PLAYERS;

num salary{PLAYERS};

num points{PLAYERS};

str team{PLAYERS};

str position{PLAYERS};

read data dk_data into PLAYERS=[player] position salary points=Projected_Fantasy_Points team;

set<str> POSITIONS = union{p in PLAYERS}{position

};

num required = 8;

/* >= 1 PG, 1 SG, 1 SF, 1C

>= 1 PG or SG

>= 1 PF or SF

>= 1 PG or SG or PF or SF = UTIL */

num requiredMin{POSITIONS} = [["PG"] 1 ["SG"] 1 ["SF"] 1 ["PF"] 1 ["C"] 1];

num budget = 50000;

var x{p in PLAYERS} binary;

max TotalPoints = sum{p in PLAYERS} x

* points

;

con budgetcon:

sum{p in PLAYERS} x

* salary

<= budget;

con positionTotal:

sum{p in PLAYERS} x

= required;

con positionMin{i in POSITIONS}:

requiredMin* <= sum{p in PLAYERS : position*

=i} x

;

con positionGuard:

sum{p in PLAYERS : position

="PG" or position

="SG"} x

>= 3;

con positionForward:

sum{p in PLAYERS : position

="PF" or position

="SF"} x

>= 3;

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

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

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

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

Hello Matthew,

Thank you for this code.

What is the p in players section? When I try to run the code I am getting the following error:

ERROR The name 'position' is an array

This is happening at the union{p in players}{position};

Thanks for your help!

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

Looks like each occurrence of [p] or [i] in the code was treated as markup and so got mangled in the display. Here it is again as a SAS code block:

```
proc optmodel;
set<str> PLAYERS;
num salary{PLAYERS};
num points{PLAYERS};
str team{PLAYERS};
str position{PLAYERS};
read data dk_data into PLAYERS=[player] position salary points=Projected_Fantasy_Points team;
set<str> POSITIONS = union{p in PLAYERS}{position[p]};
num required = 8;
/* >= 1 PG, 1 SG, 1 SF, 1C
>= 1 PG or SG
>= 1 PF or SF
>= 1 PG or SG or PF or SF = UTIL */
num requiredMin{POSITIONS} = [["PG"] 1 ["SG"] 1 ["SF"] 1 ["PF"] 1 ["C"] 1];
num budget = 50000;
var x{p in PLAYERS} binary;
max TotalPoints = sum{p in PLAYERS} x[p] * points[p];
con budgetcon:
sum{p in PLAYERS} x[p] * salary[p] <= budget;
con positionTotal:
sum{p in PLAYERS} x[p] = required;
con positionMin{i in POSITIONS}:
requiredMin[i] <= sum{p in PLAYERS : position[p]=i} x[p];
con positionGuard:
sum{p in PLAYERS : position[p]="PG" or position[p]="SG"} x[p] >= 3;
con positionForward:
sum{p in PLAYERS : position[p]="PF" or position[p]="SF"} x[p] >= 3;
solve;
create data lineup from [p]={p in PLAYERS : x[p]>0.5} position salary points team;
quit;
```

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

Hello Rob,

That worked! Thank you so much for your help!

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

Trying to beat Draft Kings?

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

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.