BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
neilxu
Calcite | Level 5

Hi All,

 

I used SAS/OR proc optmodel before in order to find a solution. But that's for a single number.

Now I need to randomly pick 100 records from 1000 records. There is another constaint, the sum of these 100 records must be a ceterain number (K).

 

So the constaints are: sum of the total number of records is 100 and the sum of records is K.

 

Where can I start? I look up some of examples but I cannot find anything similar.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

I think you want to declare a binary variable for each record and then declare your two constraints, like this:

set RECORDS;
num a {RECORDS};
read data indata into RECORDS=[record] a;
var X {RECORDS} binary;
con NumberRecords:
   sum {r in RECORDS} X[r] = 100;
con SumRecords:
   sum {r in RECORDS} a[r]*X[r] = k;

View solution in original post

1 REPLY 1
RobPratt
SAS Super FREQ

I think you want to declare a binary variable for each record and then declare your two constraints, like this:

set RECORDS;
num a {RECORDS};
read data indata into RECORDS=[record] a;
var X {RECORDS} binary;
con NumberRecords:
   sum {r in RECORDS} X[r] = 100;
con SumRecords:
   sum {r in RECORDS} a[r]*X[r] = k;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Discussion stats
  • 1 reply
  • 1333 views
  • 1 like
  • 2 in conversation