I have the dataset, attached.
There are two dates[dt] and each has bloc 3~9[bloc]. Tried with 18 conditions[condi_id].
The goal is to find the best TWO-condition combination to meet the GOAL/PENALITY:
1) Meet _tmin_orig > _tmin OR _tmin_orig > _tmin_ew OR _tmin_orig > _tmin_wt_r OR _tmin_orig > _tmin_wt_r2.
IF YES, score ONE/1; IF NOT, score -5/Negative 5
Any help are welcome. Thanks,
To MAXize the SCORE.
OUTPUT, the 1/0 for choice on the 2-cid combination.
Thanks,
group variables are date[dt] and bloc[bloc]. SCORE for each row is ready to calculation.
I need find the best two-condition[condi_id] combination to have the highest SCORE.
NOTE, here is correlation between .
This is my first OBJective. The second OBJECTIVE is to MAXimize the difference between _tmin_ORIG and one out of the 4 _tmin_xxx
with constraint of SCORE > a certain Threshold.
Cannot by hand. Need OPT. I can do it with Solver inside EXCEL. But later with huge dataset, it is feasible.
To help clarify the problem, can you please share a feasible (not necessarily optimal) solution and the corresponding objective values?
Here are 18 treatments[/conditions], take 1/0 on each treatment/condition, there are 100+ combination of two-treatment/condition combinations.
The Goal is the find the highest sum of SCORE.
Each Column's Score is either 1 [meet the criteria _tmin_orig>one of four _tmin_xxx] Or -5 if not meet the criteria.
So the output is the binary 1/0[pick or not-pick] on the 18 treatments [2 out 18 is 1 and the left over is 0]
and the final sum of SCORE.
MAXimize The SUM of each SCORE
Here's a way to use the runOptmodel action with groupBy to solve a separate problem for each dt and bloc:
data have;
set lib.mmind_temp_x;
if _tmin_orig > _tmin OR _tmin_orig > _tmin_ew OR _tmin_orig > _tmin_wt_r OR _tmin_orig > _tmin_wt_r2
then score = 1;
else score = -5;
run;
data mycas.have;
set have;
run;
proc cas;
source pgm;
/* read input data */
set IDS;
num score {IDS};
read data have into IDS=[condi_id] score;
/* define optimization model */
var Select {IDS} binary;
max TotalScore = sum {i in IDS} score[i] * Select[i];
con Cardinality:
sum {i in IDS} Select[i] = 2;
/* call MILP solver */
solve;
/* create output data */
create data want from [condi_id] score Select;
endsource;
action optimization.runOptmodel / code=pgm groupBy={'dt','bloc'};
quit;
But you can get the same results by sorting in descending order of score and keeping the top two:
proc sort data=have out=want;
by dt bloc descending score;
run;
data want;
set want;
by dt bloc;
retain rank;
if first.bloc then rank = 1;
else rank + 1;
Select = (rank <= 2);
run;
proc sort data=want;
by dt bloc condi_id;
run;
Thanks.
But I do not have PROC CAS. PC SAS. Anyway by other PROC?
I thought there is correlation between so not simply by sorting. I cannot verify the two yet.
Here are 18 treatments, and to pick 2 out 18. Either 1 of 2 picks , BY DT and BLOC, meets the condition [_tmin_orig > 1/4 _tmin_XXX],
for that DT-&-BLOC, score is 1; If both do not meet score -5, The GOAL is MAXimize the SUM of score for each DT/BLOC.
I run the code below (NOT OPT). It appears not what desired.
proc sort data=have out=want;
by dt bloc descending score;
run;
data want;
set want;
by dt bloc;
retain rank;
if first.bloc then rank = 1;
else rank + 1;
Select = (rank <= 2);
run;
proc sort data=want;
by dt bloc condi_id;
run;
The final result is 1 or 0 for the 18 treatments.
It would be 18 1/0 for the 18 treatments, with the final TOTAL SCORE [or total_scores for top candidates].
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.