w*****5 发帖数: 515 | 1 晚上看了一点书,分析并总结一下。。不对的地方请大牛指出。
1)%if 其实调用了%eval()来判断表达式
2)%if &intercept le &thres_intp_l相当于%eval( &intercept le &thres_intp_l)
,这个不会出错,因为两个都是字符型,不会自动转换,但是比较结果可能不对。
3)%sysevalf(&intercept le &thres_intp_l)可以得出正确结果,因为%sysevalf(
expression)的结果是1或者0,因此%eval(1)=1, %eval(0)=0
4) 另外3个答案:
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1) 对
%if %sysevalf(&intercept+0) le %sysevalf(&thres+0) 出错
%if %sysevalf(&intercept) le %sysevalf(&thres) 出错
这个比较有意思。因为%if()其实是调用了%eval()
因此,从结果中可以看出,%eval(a》b).如果 a和b是flo... 阅读全帖 |
|
w*****1 发帖数: 473 | 2 Thank you very much for your help!
我改了CODE如下: 现在已运行了1小时还没有停止,大家能否帮我看看? 谢谢!
data parents; set csgl.individs;
keep i QTP pedid dgeno;
if i <=2;
run;
option symbolgen mprint mlogic;
%macro new(mudaa=, mudab=, mudbb=, de=, dq=, indata=, outdata=);
data &outdata; set &indata;
lnl=log(((1-&dq)**2)*(1/sqrt(2*constant('PI'))*&de)*exp(-0.5*(((QTP-&mudaa)/
&de)**2))+
2*&dq*(1-&dq)*(1/sqrt(2*constant('PI'))*&de)*exp(-0.5*(((QTP-&mudaa)/
&de)**2))+
(&dq**2)*(1/sqrt(2*constant('PI'))*&de)*... 阅读全帖 |
|
s********l 发帖数: 245 | 3 Here is the code:
option symbolgen mprint mlogic;
%macro parametric(original=, dsn=, marker1=, marker3=, upper=, lower=,
constant=);
data &dsn;
set &original;
%let constrain1 =%sysevalf(abs(%str(&marker1 - &constant)));
%let constrain2 =%sysevalf(abs(%str(&marker3 - &constant)));
%if &marker1 NE &constant and &marker3 NE &constant %then %do;
&upper=abs(&marker1-&marker3);
&lower=abs(&marker1-&marker3);
%end;
%if &marker1 NE &constant |
|
f*****a 发帖数: 693 | 4 %macro test(min,max,jump);
%do x = &min %to &max %by &jump;
%let y=%sysevalf(&x-0.5);
%put &x &y;
%end;
%mend;
%test(1,3,1);
好像是sas macro 里的参数按字符处理,然后用%eval()来估值,但是%eval()只能估整
数值,所以你的0.5作为参数不行。但是我想在&min, &max, &jump前用上这个%
sysevalf()函数用来估值应该可以,但不知道为什么不行。我只好改成上面的方法,就
是参数里都是整数,在macro里再计算所需的指。还请高人指点能否有直接用参数
的方法。 |
|
A*******s 发帖数: 3942 | 5 sas macro里的loop是不能用非整数的,很麻烦
得用别的方法迂回一下才行
%let x=&min;
%do %while (%sysevalf(&x <= &max));
%let x=%sysevalf(&x+&jump);
%put &x;
%end; |
|
j*********a 发帖数: 232 | 6 %let sample_precision = %sysevalf(&sample_precision) + %sysevalf(avg_
precision_&k);
以上有什么错?error是:
ERROR: A character operand was found in the %EVAL function or %IF condition
where a numeric
operand is required. The condition was: avg_precision_1
穷人,一个包子都没有。。。 |
|
n******e 发帖数: 53 | 7 try
%if %SYSEVALF(&intercept) le %SYSEVALF(&thres_intp_l) |
|
a******n 发帖数: 11246 | 8 其实就是要把字符型的-0.2变为数值型,但我不知道用什么函数。
只会用这个傻x方法解决:(
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1) |
|
g*******s 发帖数: 59 | 9 dataset ts; ts 包含dependent variable : orig_fl_bal_0,
independent variable: c1 c2 c3 c4
目的是实现proc model fit的自动化;
程序如下:
%let iv_list = c1 c2 c3 c4;
%global finalResult;
%global macrolist2;
%macro generateResults(varlist);
%let result = a&k.;
%let macrolist = a&k.;
%let k = %str(1);
%do %while(%scan(&varlist, (%sysevalf(&k))) ne );
%let iv = %scan(&varlist,(&sysevalf(&k)));
%let finalResult = &result + b&k.*&iv;
%let result = &finalResult;
%let macrolist2 = ¯olist b&k.;
%let macrolist = ¯ol... 阅读全帖 |
|
d*******1 发帖数: 293 | 10 我用下面的code, 但是出错,好像是参数类型传递错误
%macro derv(lambda);
%global dl;
%let temp1 = %sysfunc(exp(-&lambda));
%let dl = %sysevalf(10/&lambda + 25*&temp1/(1-&temp1) - 27.21);
%mend derv;
Data;
Lam_1 = 0.1;
%derv(Lam_1);
出错 (我把它改成 %derv(0.1) 就没有问题, 但是dl的值有问题,不知道用的时候,可不可以这样用)
ERROR: A character operand was found in the %EVAL function or %IF condition
where a numeric operand is required.
我这儿需要把Lam_1转换成numeric type吗? 用什么函数可以转化?
另外, 对于Macro parameters, 好像只有输入参数,可以把参数设置成输出参数吗,要不
然,觉得很不方便,要不断使用global v |
|
A*********u 发帖数: 8976 | 11 如果只是计算,为啥一定要用macro呢
我用下面的code, 但是出错,好像是参数类型传递错误
%macro derv(lambda);
%global dl;
%let temp1 = %sysfunc(exp(-&lambda));
%let dl = %sysevalf(10/&lambda + 25*&temp1/(1-&temp1) - 27.21);
%mend derv;
Data;
Lam_1 = 0.1;
%derv(Lam_1);
出错 (我把它改成 %derv(0.1) 就没有问题, 但是dl的值有问题,不知道用的时候,可不
可以这样用)
ERROR: A character operand was found in the %EVAL function or %IF condition
where a numeric operand is required.
我这儿需要把Lam_1转换成numeric type吗? 用什么函数可以转化?
另外, 对于Macro parameters, 好像只有输入参数,可以把参数设置成输出参数吗,要不 |
|
f*******e 发帖数: 7 | 12 the problem is not the %if, but the %let
%let constrain1 =%sysevalf(abs(%str(&marker1 - &constant)));
SAS doesn't know you are calling a function abs() here. try %sysfunc(abs()).
Good luck |
|
|
f*****a 发帖数: 693 | 14 第一次回复错了,应该改成:
%macro test(min,max,jump);
%do x = &min %to &max %by &jump;
%let y=%sysevalf(&x-0.5*(&i-1));
%put &x &y;
%end;
%mend;
%test(1,3,1); |
|
s******y 发帖数: 352 | 15 Yes, But still have to work little bit harder. not sure if there are other
ways around.
proc format;
value a
0-30000 = 'a*.1'
30000-60000 = '30000*.1 + (a-30000)*.25'
60000-80000 = '30000*.1 + 30000*.25 + (a-60000)*.30'
;
run;
data test;
do a=10 to 80000 by 5000;
b='%sysevalf('||strip(tranwrd(put(a,a.),'a',a))||')';
c=resolve(b);
output;
end;
run; |
|
D******n 发帖数: 2836 | 16 create a .vim directory under you home directory(there is a dot before
vim)
and then create a syntax directory under it
and then create a sas.vim file under the syntax directory
==============sas.vim======================
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syn case ignore
syn region sasString start=+"+ skip=+\\|\"+ end=+"+
syn region sasString start=+'+ skip=+\\|\"+ end=+'+
" Want region from 'cards;' to ';' to be captured (Bob Heckel)
sy... 阅读全帖 |
|
A*******s 发帖数: 3942 | 17 i don't quite get it.
did u use %sysevalf()? |
|
w****g 发帖数: 81 | 18 I did, got same results, actually no need to use %sysevalf() for number. |
|
A*******s 发帖数: 3942 | 19 i got different results with or without %sysevalf() |
|
w****g 发帖数: 81 | 20 hey, I use this one and it works: %IF %sysevalf( &sum_current_grp. < &&grp&i
.) %then
thanks for all the advices! |
|
d******9 发帖数: 404 | 21 Hehe, everything in macro is text, so macro compares them as characters.
As numeric, 5.73 < 42.489.
However, as character string, 5.73 > 42.489.
Therefore, you need use %sysevalf if you want to compare their numeric
values.
&i |
|
p********a 发帖数: 5352 | 22 avg_precision_&k 是个变量啊,不是MACRO变量。再说了,+号应该在%SYSEVALF里面 |
|
k*******a 发帖数: 772 | 23 can also try
%if %sysevalf(&intercept le &thres_intp_l) |
|
D******n 发帖数: 2836 | 24 try this
%if %sysevalf(&a>&b,boolean)>0 %then .....
this one is tested.
baozi pls. |
|
h********o 发帖数: 103 | 25 Try this:
============
data test;
do x = 99 to 1 by -1;
output;
end;
run;
%macro split(inputdata, N, var);
proc sort data = &inputdata;
by &var;
run;
data _null_;
if 0 then set &inputdata nobs = count;
call symput("numobs", put(count,8.));
run;
%let m = %sysevalf(&numobs/&N, ceil);
%do i = 1 %to &N;
data test&i;
set &inputdata;
if %eval(&m*(&i-1)) < _N_ <= %eval(&m*&i);
run;
%end;
%mend;
%split(test,5,x); |
|
d********e 发帖数: 9 | 26 改成
data B;
set A;
B = resolve(catt('%SYSEVALF(',A,')'));
run;
应该能计算non-integer吧 |
|