BookmarkSubscribeRSS Feed
hellohere
Pyrite | Level 9

@RobPratt  @Ksharp 

 

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, 

 

dataset.png

 

 

 

 

 

 

13 REPLIES 13
Ksharp
Super User
So what is your Object Function ? and what is your desired output ?
hellohere
Pyrite | Level 9

To MAXize the SCORE. 

 

OUTPUT, the 1/0 for choice on the 2-cid combination. 

 

Thanks,

Ksharp
Super User
2-cid combination is picking up 2 condi_id or 2 bloc ?
Your group variable is dt or bloc or dt+bloc ?

Since you only could get 1 or -5 ,that means pick up two 1s is the best choice. You can calculate the score for each row and pick the best combination by hand , right ?
hellohere
Pyrite | Level 9

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. 

RobPratt
SAS Super FREQ

To help clarify the problem, can you please share a feasible (not necessarily optimal) solution and the corresponding objective values?

hellohere
Pyrite | Level 9

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. 

hellohere
Pyrite | Level 9

MAXimize The SUM of each SCORE

RobPratt
SAS Super FREQ

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;
hellohere
Pyrite | Level 9

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. 

 

hellohere
Pyrite | Level 9

@RobPratt  @Ksharp 

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;

 

Ksharp
Super User
Can you post an example to explain why it is not what you are looking for?
E.X.
dt block condi_id score
1 1 1 4
1 1 2 3
1 1 3 2
1 1 4 1

Why the first two obs is not what you are looking for ?
hellohere
Pyrite | Level 9

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]. 

hellohere
Pyrite | Level 9

Please disregard this thread. 

 

@Ksharp  @RobPratt 

 

Let me re-group and repost with clean clarification on the quest. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 13 replies
  • 1374 views
  • 2 likes
  • 3 in conversation