# 简单线性规划问题SAS编程之二

ps：原文中的表达不够清晰，且10根算起来不过瘾，故修改。

options nomprint;

data ex;
input  _type_\$ _rhs_;
cards;
ge 100
ge 100
ge 100
ge 100
ge 100
min .
upperbd .
integer .
;
run;
%macro sxl(out=out);

proc sql;
create table &out.
(
numm num format = 12.       label = ‘number’,
i  num format = 12. label = ‘length’

);
quit;

%do i = 1300 %to 1650;

data _aa (keep=c d e f g i );
a1=int(&i./303);
a2=int(&i./251);
a3=int(&i./202);
a4=int(&i./151);
a5=int(&i./107);
w=&i.-107;
do c=0 to a1;
do d=0 to a2;
do e=0 to a3;
do f=0 to a4;
do g=0 to a5;
x=303*c+251*d+202*e+151*f+107*g;
y=&i.-x;
if x>w and x<=&i. then do;
i+1;
output;
end;
end;
end;
end;
end;
end;
run;

proc sort data=_aa out=_aa(drop=i);
by descending i ;
run;

data _null_;
set _aa(drop=_all_) nobs=rows;
call symput(‘nobs’,rows);
stop;
run;

data _collect(drop=i);
LENGTH _VAR_ \$8.;
set _aa;
i+1;
_VAR_=catt(‘COL’,i);
run;

proc transpose data=_aa out=_aa1;
run;
data _bb(drop=i);
do i =1 to &nobs.;
a=1;
b=100;
c+1;
output;
end;
run;
proc transpose data=_bb out=_bb1;
run;

data ex1(drop=_NAME_);
set _aa1 _bb1;
run;

data ex2;
merge ex1 ex ;
run;

ods listing close;
ods output solutionsummary=_p;
proc lp data=ex2  IMAXIT=500;
run;
ods _all_ close;
ods listing ;

proc sql noprint;
select CVALUE1
into :numm from _p;

data _tem;
numm=&numm.;
i  = &i.;
run;

proc sql;
insert into
&out.
select
*
from
_tem;
quit;

%end;
data &out.;
set &out.;
length=numm*i;
if numm ne lag(numm) then output;
run;

proc sort data=&out. out=&out.;
by length ;
run;
proc print data=&out.;
run;
%mend sxl;
%sxl;

result:

Obs            numm               i    length

1              69            1471    101499
2              67            1515    101505
3              65            1562    101530
4              72            1411    101592
5              63            1613    101619
6              77            1320    101640
7              75            1360    102000
8              78            1310    102180
9              70            1460    102200
10              68            1509    102612
11              66            1557    102762
12              73            1408    102784
13              64            1608    102912
14              76            1357    103132
15              79            1307    103253
16              71            1457    103447
17              80            1300    104000
18              74            1406    104044

## 《简单线性规划问题SAS编程之二》上的2个想法

1. 优化了下代码，现在要跑80s，改变不是很显著。:(