全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1394 5
2012-02-21
写了一段宏,怎么都测试不出结果。数据格式如下,计算过程是:1。先判断count12是否有数,有的话,取其具體数的绝对值,即是其对应的月份的IOP进行相减。如:count21=15,其前面count11=9,则IOP_15m-IOP_9m.中間鑲嵌了一段判斷具體是哪一類相減,一共6種,包括(IOP_B_B IOP_PGA IOP_Miotic IOP_CAI IOP_Diamox IOP_Adren).

每次程序都報錯說:ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: count21
我檢查過了,count21都是數值型,所以不是這個的問題,懷疑是數據讀取的問題,但是自己怎麼也發現不了。還望有高手來救我。

count11

count21

count31

IOP_3m

IOP_6m

IOP_9m

IOP_12m

IOP_15m

IOP_18m

9

15

18

15

16

21

18

19

20

17

17

18

19

15

16

-12

15

18

16

21

18

15

16

21

3

6

17

18

19

17

17

18




%macro IOP12(i=);
  %let x=%eval(count&i.1);
  %let j=%eval(&i-1);
  %let b=%eval(count&j.1);
data IOP1_begin3m;
set IOP1_begin3m;
if abs(coun&i.1)>0 then do;
   if B_B_&x.M_c ~= B_B_&b.M_c then IOP_B_B=IOP_&x.M-IOP_&b.M;
     else if  PGA_&x.M_c ~= PGA_&b.M_c then IOP_PGA=IOP_&x.M-IOP_&b.M;
     else if  Miotic_&x.M_c ~= Miotic_&b.M_c then IOP_Miotic=IOP_&x.M-IOP_&b.M;
     else if  CAI_&x.M_c ~= CAI_&b.M_c then IOP_CAI=IOP_&x.M-IOP_&b.M;
     else if  Diamox_&x.M_c ~= Diamox_&b.M_c then IOP_Diamox=IOP_&x.M-IOP_&b.M;
     else if  Adren_&x.M_c ~= Adren_&b.M_c then IOP_Adren=IOP_&x.M-IOP_&b.M;
end;
run;
%mend IOP12;

%IOP12(i=2);
二维码

扫码加我 拉你入群

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

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

全部回复
2012-2-21 15:48:27
这段code好眼熟……你找一下上周的帖子,好像解决过几乎一样的问题……
二维码

扫码加我 拉你入群

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

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

2012-2-21 16:06:22
zhangzachary 发表于 2012-2-21 15:48
这段code好眼熟……你找一下上周的帖子,好像解决过几乎一样的问题……
哈哈,說對了,基本上就是按照zhangzachary寫的改的,但是還是這個問題,所以才又發了上來
二维码

扫码加我 拉你入群

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

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

2012-2-22 11:05:52
木有人理我
二维码

扫码加我 拉你入群

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

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

2012-2-22 23:20:07
逻辑有问题:比如,第三行COUNT11=-12,也就是&b是-12。这种负数怎么可能充当变量名字的一部分。京剧
二维码

扫码加我 拉你入群

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

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

2012-2-24 18:45:05
这是你想要的吧!
data a;
input count11 count21 count31 IOP_3m IOP_6m IOP_9m IOP_12m IOP_15m IOP_18m;  
datalines;
9 15 18 15 16 21 18 19 20
. . . 17 17 18 19 15 16
-12 15 18 16 21 18 15 16 21
3 6 . 17 18 19 17 17 18
;


data b;
set a;
array iop{*} IOP_3m IOP_6m IOP_9m IOP_12m IOP_15m IOP_18m ;
array countidx{*} count11 count21 count31;
array pga{3} 8;
retain n;
n=0;

do i = dim(countidx) to 1 by -1 ;
        do j=1 to i-1;
                n=n+1;
                if countidx{i}~=. and countidx{j} ~=. then
                        pga{n} =iop{abs(countidx{i}/3)}- iop{abs(countidx{j}/3)} ;
        end;
end;



run;
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群