BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phoenix_LJ
Obsidian | Level 7
proc optmodel;
	/*declare	*/
	set rows = 1..10;
	set cols = 1..6;
	var X{rows,cols} >=0 <=50;
	max z=sum(x[6,1],x[6,2],x[6,3]);


	/*constrains	*/
	con varcon1{i in 1..6}: 0<=X[1,i]<=10;
	con varcon2{i in 1..6}: 0<=X[1,i]<=25;
	con varcon3{i in 1..6}: 0<=X[1,i]<=15;
	con varcon4{i in 1..6}: 0<=X[1,i]<=23;
	con varcon5{i in 1..6}: 0<=X[1,i]<=10;
	con varcon6{i in 1..6}: 0<=X[1,i]<=20;
	con varcon7{i in 1..6}: 0<=X[1,i]<=20;
	con varcon8{i in 1..6}: 0<=X[1,i]<=20;
	con varcon9{i in 1..6}: 0<=X[1,i]<=5;
	con varcon10{i in 1..6}: 0<=X[1,i]<=2;

	/*constrains	*/
	con colcon1{i in 1..10}:  0<=x[i,1]<=50;
	con colcon2{i in 1..10}:  0<=x[i,2]<=35;
	con colcon3{i in 1..10}:  0<=x[i,3]<=15;
	con colcon4{i in 1..10}:  0<=x[i,4]<=8;
	con colcon5{i in 1..10}:  0<=x[i,5]<=12;
	con colcon6{i in 1..10}:  0<=x[i,6]<=30;

	/*constrains	*/
	con equal1:	sum{i in 1..6}(x[1,i]) = 10;
	con equal2:	sum{i in 1..6}(x[2,i]) = 25;
	con equal3: sum{i in 1..6}(x[3,i]) = 15;
	con equal4:	sum{i in 1..6}(x[4,i]) = 10;
	con equal5:	sum{i in 1..6}(x[5,i]) = 20;
	con equal6:	sum{i in 1..6}(x[6,i]) = 20;
	con equal7:	sum{i in 1..6}(x[7,i]) = 20;
	con equal8:	sum{i in 1..6}(x[8,i]) = 5;
	con equal9:	sum{i in 1..6}(x[9,i]) = 2;
	con equal10:sum{i in 1..6}(x[10,i]) = 23;

	SOLVE;
	print x;
QUIT;

Please run this code,

the question is 

  • How do I keep array X two decimal places 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

The SUM() function triggers the NLP solver to be used.  If you change the objective declaration as follows, the LP solver will instead be used, and the (totally unimodular) structure of your problem naturally yields an integer solution:

/*	max z=sum(x[6,1],x[6,2],x[6,3]);*/
	max z = x[6,1] + x[6,2] + x[6,3];
X
  1 2 3 4 5 6
1 2 2 2 2 2 0
2 25 0 0 0 0 0
3 15 0 0 0 0 0
4 10 0 0 0 0 0
5 20 0 0 0 0 0
6 20 0 0 0 0 0
7 20 0 0 0 0 0
8 5 0 0 0 0 0
9 2 0 0 0 0 0
10 23 0 0 0 0 0

View solution in original post

3 REPLIES 3
Ksharp
Super User

Better post it at OR forum. And calling @RobPratt 

RobPratt
SAS Super FREQ

The SUM() function triggers the NLP solver to be used.  If you change the objective declaration as follows, the LP solver will instead be used, and the (totally unimodular) structure of your problem naturally yields an integer solution:

/*	max z=sum(x[6,1],x[6,2],x[6,3]);*/
	max z = x[6,1] + x[6,2] + x[6,3];
X
  1 2 3 4 5 6
1 2 2 2 2 2 0
2 25 0 0 0 0 0
3 15 0 0 0 0 0
4 10 0 0 0 0 0
5 20 0 0 0 0 0
6 20 0 0 0 0 0
7 20 0 0 0 0 0
8 5 0 0 0 0 0
9 2 0 0 0 0 0
10 23 0 0 0 0 0
RobPratt
SAS Super FREQ

Also notice that your varcon10 constraint makes the other nine varcon* constraints redundant.  Are you sure that this model correctly captures the problem you want to solve?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

Discussion stats
  • 3 replies
  • 793 views
  • 1 like
  • 3 in conversation