楼主: 小甲克虫
2347 13

请教高人SAS变成实现下列模型 [推广有奖]

  • 9关注
  • 12粉丝

教授

12%

还不是VIP/贵宾

-

威望
0
论坛币
8160 个
通用积分
116.0411
学术水平
10 点
热心指数
20 点
信用等级
8 点
经验
41018 点
帖子
703
精华
0
在线时间
1457 小时
注册时间
2005-9-20
最后登录
2023-6-16
毕业学校
中南财经政法大学

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
[img]file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/178684023/QQ/WinTemp/RichOle/4[~CYGG5CA`XJ(K%TW]E8Y2.jpg[/img]
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:请教高人 Application documents Settings Document 模型

未命名.jpg (43.08 KB)

未命名.jpg

回帖推荐

jingju11 发表于2楼  查看完整内容

Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical model. I try to "hard-code"it and it is de facto fast since only 16 values are involved for thecombination. JingjuThe results like:

本帖被以下文库推荐

沙发
jingju11 发表于 2012-11-20 07:12:32 |只看作者 |坛友微信交流群

Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical model. I try to "hard-code"it and it is de facto fast since only 16 values are involved for thecombination.

Jingju

  1. %macro runn(tx);
  2. /*This format only works on distinct xs*/
  3.         proc format;
  4.                 value nameF
  5.                 1 ='x01' 4='x02'  7='x03'  13='x04'  20='x05'  29='x06'  52='x07'  81='x08'  205='x09'  
  6.                 338='x10'  504='x11'  543='x12'  2488='x13'  3300='x14'  5360='x15'  5922='x16'
  7.         ;
  8.         %let nobs = %eval(2**16-1);
  9.         data _null_;
  10.                 length Name $64.;
  11.                 array x[16] x01-x16(1 4 7 13 20 29 52 81 205 338 504 543 2488 3300 5360 5922);
  12.                 array tname[&nobs] $64._temporary_;
  13.                 array t1n[&nobs] _temporary_;  array t2n[&nobs] _temporary_;
  14.                 ii = 0;
  15.                 %do k = 1 %to 16;
  16.                         array n&k.n[&k] $32. _temporary_;
  17.                         do j=1 to comb(16,&k);
  18.                                 ii ++1;
  19.                                 rc=allcomb(j, &k, of x[*]);
  20.                                 s =0;
  21.                                 do i =1 to &k;                                       
  22.                                         s ++x[i];
  23.                                         n&k.n[i] =put(x[i], nameF.);                                       
  24.                                 end;
  25.                                 call sortc(of n&k.n[*]);
  26.                                 tname[ii] = catx('+', of n&k.n[*]);                        
  27.                                 t1n[ii] =abs(s-&tx);t2n[ii] =s;
  28.                    end;
  29.                 %end;
  30.                 _min = min(of t1n[*]);
  31.                 put 80*'-';
  32.                 put @2 "Combinations" @72 'sum';
  33.                 put;               
  34.                 do i =1 to &nobs;
  35.                         if t1n[i] =_min then do;
  36.                                 name = tname[i]; sum = t2n[i];                                                
  37.                                 put @2 name $64.-L @70 sum F6.-R;                                
  38.                         end;        
  39.                 end;
  40.                 put 80*'-';        
  41.         run;
  42. %mend runn;
  43. %runn(12090);
  44. %runn(91);
复制代码
The results like:
--------------------------------------------------------------------------------
Combinations                                                                                                      sum

x04+x06+x10+x13+x14+x16                                                                         12090
x01+x03+x07+x09+x12+x15+x16                                                                 12090
x02+x03+x05+x06+x09+x12+x15+x16                                                        12090
x01+x02+x04+x08+x09+x11+x15+x16                                                        12090
x04+x06+x07+x08+x09+x13+x14+x16                                                        12090
x01+x02+x04+x06+x07+x09+x11+x15+x16                                                12090
x01+x02+x03+x05+x06+x10+x12+x13+x14+x15                                       12090
x01+x02+x03+x05+x06+x07+x08+x09+x12+x13+x14+x15                      12090
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Combinations                                                          sum

x02+x03+x08                                                             92
x03+x04+x05+x07                                                     92
x02+x03+x06+x07                                                     92
x01+x02+x04+x05+x07                                             90
--------------------------------------------------------------------------------
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
bakoll + 3 + 3 精彩帖子
Imasasor + 12 + 60 + 2 + 2 + 2 对论坛有贡献

总评分: 经验 + 15  论坛币 + 63  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

使用道具

藤椅
小甲克虫 在职认证  发表于 2012-11-20 08:47:32 |只看作者 |坛友微信交流群
jingju11 发表于 2012-11-20 07:12
Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical m ...
非常感谢!我仔细看看!太感谢您了。之前我用了LINGO软件求最优解,但是只能求精确的不能求近似的。谢谢你的方法!

使用道具

板凳
zhangwenteng 发表于 2012-11-20 09:25:54 |只看作者 |坛友微信交流群
我怎么看不到题目呢?

使用道具

报纸
maidenhan 发表于 2012-11-20 09:26:45 |只看作者 |坛友微信交流群
jingju11 发表于 2012-11-20 07:12
Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical m ...
这里提供一种不一样的思路:
首先,找出各变量的所有不重复的组合;
然后,对每种组合进行求和;
最后,对于任意给定的值,找出与此值距离最小的组合,并且输出。

plus,佩服京剧大人的output功力,我是做不到你的程度啦。
程序如下:
  1. data test1;
  2. input v1-v16;
  3. cards;
  4. 1 4 7 13 20 29 52 81 205 338 504 543 2488 3300 5360 5922
  5. ;run;
  6. %macro test(n);
  7. data _null_;
  8. set test1;
  9. %do ii = 1 %to &n.;
  10.   call symputx("v_&ii.", v&ii.);
  11. %end;
  12. run;
  13. data test2;
  14. %do ii = 1 %to &n.;
  15.   do x&ii. = 0 to 1;
  16. %end;
  17.    output;
  18. %do ii = 1 %to &n.;
  19.   end;
  20. %end;
  21. run;
  22. data test3;
  23. format total 20.;
  24. set test2;
  25. total = 0;
  26. %do ii = 1 %to &n.;
  27.   total = total + x&ii. *&&v_&ii..;
  28. %end;
  29. row_id + 1;
  30. run;
  31. %mend;
  32. %test(n=16);
  33. %macro ans_output(n, input_n);
  34. data test4;
  35. format dis 20.;
  36. set test3;
  37. dis = abs(total - &input_n.);
  38. run;
  39. proc sql;
  40. create table test5 as
  41. select *
  42.   from test4
  43.   where dis = (select min(dis) from test4);
  44. quit;
  45. proc print data = test5;
  46. var dis total x1-x&n.;
  47. run;
  48. %mend;
  49. %ans_output(n=16, input_n = 91);
复制代码

使用道具

地板
maidenhan 发表于 2012-11-20 09:30:03 |只看作者 |坛友微信交流群
小甲克虫 发表于 2012-11-20 08:47
非常感谢!我仔细看看!太感谢您了。之前我用了LINGO软件求最优解,但是只能求精确的不能求近似的。谢谢你 ...
用Lingo的话,目标函数可能不太好写。毕竟,你要找的,是距离的绝对值最小。

使用道具

7
小甲克虫 在职认证  发表于 2012-11-20 09:32:51 |只看作者 |坛友微信交流群
maidenhan 发表于 2012-11-20 09:30
用Lingo的话,目标函数可能不太好写。毕竟,你要找的,是距离的绝对值最小。
不用目标函数好像,对数据集进行操作。一共16个待定变量,他们的值只有0和1.

使用道具

8
小甲克虫 在职认证  发表于 2012-11-20 09:35:52 |只看作者 |坛友微信交流群
zhangwenteng 发表于 2012-11-20 09:25
我怎么看不到题目呢?
可以的,下边的图片!

使用道具

9
小甲克虫 在职认证  发表于 2012-11-20 10:48:09 |只看作者 |坛友微信交流群
jingju11 发表于 2012-11-20 07:12
Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical m ...
哥哥 是否可以讲下COMB函数和ALLCOMB函数用法。 谢谢!

使用道具

10
小甲克虫 在职认证  发表于 2012-11-20 16:26:39 |只看作者 |坛友微信交流群
jingju11 发表于 2012-11-20 07:12
Do you have any fast algorithm to find the solution? I amnot sure why this was called mathematical m ...
小弟愚钝,高人可否把这个程序解读下?谢谢!

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-6-8 20:16