楼主: yangz98
2212 2

[问答] 求助:topsis法SAS宏 [推广有奖]

  • 12关注
  • 3粉丝

已卖:16份资源

讲师

48%

还不是VIP/贵宾

-

威望
0
论坛币
331 个
通用积分
1.1210
学术水平
29 点
热心指数
32 点
信用等级
27 点
经验
303 点
帖子
509
精华
0
在线时间
519 小时
注册时间
2012-3-9
最后登录
2023-4-5

楼主
yangz98 发表于 2013-10-2 16:30:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
本人SAS菜鸟一枚,十一假期,闲来没事就在CNKI上面找了一篇文章《Top sis 法在SAS 宏中的统计实现》,想要学习一下SAS宏,但是一直出错,特别是%let语句定义宏变量以及%let语句中镶嵌引用宏变量,请求各位大侠帮忙修改一下下面这段程序,下附原参考文献和自己从里面弄得程序: Topsis法在SAS宏中的统计实现_曾邦伟.pdf (130.5 KB) WARNING: Apparent symbolic reference VAR not resolved.ERROR: A character operand was found in the %EVAL function or %IF condition where a numerc       operand is required. The condition was: & &var&i.=ERROR: The condition in the %DO %UNTIL loop, & &var&i.=, yielded an invalid or missing value, .       The macro will stop executing.
%macro topsis(database=,vara=,vark=,weight=0);/*database:被分析变量所在的数据集   
vara:要分析的变量   
vark:结果中保留的变量     
weight:权重值可取0和1,默认去0*/
%let i=1;%let var&i.=%scan(&vara.,&i.,'');
%do %until(& &var&i.=);   
%let i=%eval(&i.+1);
%let var&i.=%scan(&vara.,&i.,'');
%end;
%let var_num=%eval(&i.-1);


%if &weight. %then %do;   
data top_1 top_2;      
set &database. end=last;      
if last then output top_2;      
else output top_1;      
run;      
%end;
%else %do;  
data top_1;      
set &database.;      
data top_2;        
%do i=1 %to &var_num.;        & &var. &i.;        %end;        run;        %end;
data _null_;set top_1 end=last;
if last then call symput('obj_num',compress(_n_));
%let sqr_str=;
data top_a;set top_1 end=last;%do i=1 %to &var_num.;  
& &var. &i.._2=& &var.&i.**2;   
%let sqr_str=&sqr_str & &var&i..2;%end;

proc transpose data=top_a(keep=&sqr_str.) prefix=top_m out=top_b;run;
proc transpose data=top_a(keep=&vara.) prefix=top_n out=top_c;run;
proc transpose data=top_2(keep=&vara.) prefix=top_w out=top_w;run;
data top_d;set top_b;z=sum(of top_m1-top_m&obj_num.);
%let min_str=;%let max_str=;
data top_e;merge top_c top_d top_w;%do i=1 %to &obi_num.;z&i.=top_n&i./sqrt(z);
%end;
max=max(of z1-z&obj_num.);min=min(of z1 z&obj_num.);
%do i=1 %to %obj_num.;d_max&i.=top_w1*(z&i.-max)**2;d_min&i.=top_w1*(z&i.-min)**2;
%let max_str=&max_str d_max&i;%let min_str=&max_str d_min&i;%end;
proc transpose data=top_e(keep=&max_str.) prefix=max out=top_f;run;
proc transpose data=top_e(keep=&min_str.) prefix=min out=top_g;run;
data top_h(keep=&vark. d_max d_min c);merge top_1 top_f top_g;
max_sum=sum(of max1-max&var_num.);
min_sum=sum(of min1-min&var_num.);

d_max=sqrt(max_sum);d_min=sqrt(min_sum);C=d_min/(d_max+d_min);
proc rank data=top_h descending out=topsis_result;ranks order;var c;run;
proc print;title "The Topsis Report of &vark.";run;
%mend topsis;
data SF236;input city $ x1-x8;
format city $ 5. x1-x8 6.2;
cards;
CS 72.07 64.08 75.40 46.85 69.10 78.83 81.78 75.63
SZ 74.58 63.17 68.04 53.07 70.87 76.57 71.86 68.91
SY 77.79 54.77 72.32 61.83 69.35 73.65 63.41 71.75
GZ 82.01 71.03 73.10 58.93 68.83 73.00 72.27 72.64
CD 79.78 79.06 78.27 56.77 70.85 82.57 82.96 77.54
TJ 66.37 59.91 73.16 69.27 79.09 67.92 68.14 57.12
SH 67.11 76.15 72.37 54.63 68.13 77.22 77.71 78.63
;
run;
proc format;
value $ cityfmt CS='ChangSha'                SZ='SuZhou'                                SY='ShenYang'                                GZ='GuangZhou'                                CD='ChengDu'                                TJ='TianJin'                                SH='ShangHai';run;
proc print data=SF236;format city $cityfmt.;title "Data of SF236";run;
%topsis(database=SF236,vara=x1-x8,vark=city,weight=0);



二维码

扫码加我 拉你入群

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

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

关键词:topsis Tops SAS宏 OPS Top topsis SAS宏 疑问???

沙发
邓贵大 发表于 2013-10-2 22:45:52
dude, copy it from here http://www.yixue68.com/jiaoyu/html/?21856.html and save yourself lots of trouble
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

藤椅
yangz98 发表于 2013-10-2 23:03:47
邓贵大 发表于 2013-10-2 22:45
dude, copy it from here http://www.yixue68.com/jiaoyu/html/?21856.html and save yourself lots of tro ...

Thank u so much, an useful method to check the SAS macro in papers has been learnt.

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 16:16