Mathematical Optimization, Discrete-Event Simulation, and OR

Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio
BookmarkSubscribeRSS Feed
xyz3
Calcite | Level 5

Hi, I am trying to minimize a function (that I created with proc fcmp) per group of observations that are defined by a category column. I tried using this example (http://support.sas.com/kb/42/332.html) for by group processing with proc optmodel but I'm not sure if the way I'm indexing the observations is correct. 

 

This is my code:

options cmplib=work.funcs;
%let byvar=pat_ID;

proc optmodel cdigits=10 fdigits=10 pdigits=9;

	set OBS;
	str pat_ID {OBS};
	num UW_acc{OBS};
	num EP_incr{OBS};
	num Time{OBS};

	read data work.pat_data into OBS=[_n_] pat_ID=pat_ID;
	read data work.pat_data into OBS=[_n_] UW_acc=UW_pattern_acc;
	read data work.pat_data into OBS=[_n_] EP_incr=EP_pattern_incr;
	read data work.pat_data into OBS=[_n_] Time=Year;

	/* Collect values of BY variable into an index set */
	set BYSET = setof {i in OBS} &byvar.[i];
	put BYSET=;
	str by;

	/* variables */
	set OBS_BY = {i in OBS: &byvar.[i] = by};

	var a >=&LOW_A. <= &UP_A. init &INITA.;
	var b >=&LOW_B. <= &UP_B. init &INITB.;
	
	minimize FuncVal = pat_opt(a, b, UW_acc[OBS_BY], EP_incr[OBS_BY], Time[OBS_PY]);

	/*variables to store result*/
	num a_sol {BYSET};
	num b_sol {BYSET};

	do by = BYSET;
		put by=;
		solve with nlp / multistart=(maxstarts=&MAXSTART.) seed=&SEED. maxiter=&MAXITER. opttol=&OPTTOL. feastol=&FEASTOL.;
		print a b;
		a_sol[by] = a.sol;
		b_sol[by] = b.sol;
	end;

	create data work.solver_results from [by] a=a_sol b=b_sol;

run; 

proc print data=work.solver_results;
run;

quit;

TITLE;

 

When running the code I get "subscript 1 may not be a set" as an error for this line for each variable uw_acc, ep_incr and time.

minimize FuncVal = pat_opt(a, b, UW_acc[OBS_BY], EP_incr[OBS_BY], Time[OBS_PY]);

 

Let me know, if you need more info!

Thanks!

 

(I'm using SAS Version 9.4)

1 REPLY 1
RobPratt
SAS Super FREQ

The argument to UW_acc should be an element of the set OBS. but you are passing OBS_BY, which is instead a subset of OBS.  Same story for EP_incr and Time.  What does your pat_opt function expect as input?

 

By the way, you can combine the READ DATA statements as follows:

read data work.pat_data into OBS=[_n_] pat_ID=pat_ID UW_acc=UW_pattern_acc EP_incr=EP_pattern_incr Time=Year;

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
  • 1384 views
  • 0 likes
  • 2 in conversation