标题: help for a macro [打印本页] 作者: gogotiger 时间: 2014-7-12 07:05 标题: help for a macro data a;
input unid $ x y;
cards;
a 100 10
a 300 15
b 270 9
b 210 7
c 840 20
; run; %macroab;
proc sql;
create table b as
select *,
%if unid='a' %then %do; (x/y)*1.2 as z format=8.2 %end;
%else %if unid='b' %then %do; (x/y)*1.5 as z format=8.2 %end;
%else %if unid='c' %then %do; (x/y)*2 as z format=8.2 %end;
from a;
quit; %mend;
%ab the code above is trying to calculate z=x/y with a adjustment(if unid=a then multiple by 1.2; if b then 1.5; if c then 2), but did not work. so, just wonder anyone can help, thanks a lot! 作者: mono 时间: 2014-7-17 08:27
data a;
input unid $ x y;
cards;
a 100 10
a 300 15
b 270 9
b 210 7
c 840 20
;
run;
PROC SQL;
CREATE TABLE c AS
SELECT *,
CASE
WHEN unid='a' THEN (x/y)*1.2
WHEN unid='b' THEN (x/y)*1.5
WHEN unid='c' THEN (x/y)*2.0
END AS weighted
FROM a;
QUIT;作者: gogotiger 时间: 2014-7-19 23:03
谢谢楼上。
我想知道的是为何用macro就出错呢?如何修改?作者: sunxiaotong 时间: 2014-8-27 17:48
感觉是你IF 语句后面的分号不对吧,SQL用‘;’一般都是语句结束的时候才用作者: gogotiger 时间: 2014-9-6 22:43
谢谢楼上,哪该如何改?作者: tianyawoxin 时间: 2014-9-14 13:51
你这个macro, if- then -else, 基本就是data步的套路吧作者: gogotiger 时间: 2014-9-20 20:33
是的,就是看上去及其简单,不知道错在哪里。