SAS中文论坛

标题: looking for help for a simple macro code [打印本页]

作者: shiyiming    时间: 2013-10-31 07:57
标题: looking for help for a simple macro code
%macro pct;
%do i=0 %to 1 %by 0.1 ;
data diff;
  pp=&i.;
run;
%end;
%mend;
%pct

I am trying to get a dataset diff with a row value of pp , however, it gave me error message as displayed below, and  wonder anyone could help.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
       0.1
ERROR: The %BY value of the %DO I loop is invalid.

thx a lot!!!!
作者: shiyiming    时间: 2013-10-31 15:21
标题: Re: looking for help for a simple macro code
[code:13qs2m3k]%macro pct;
    %let i=0;
    %let i=%sysevalf(&i+0.1);
    %do %until(&i gt 1);
        data diff;
            pp=&i.;
        run;
        %let i=%sysevalf(&i+0.1);
    %end;
%mend;
%pct[/code:13qs2m3k]
作者: shiyiming    时间: 2013-10-31 22:22
标题: Re: looking for help for a simple macro code
nice.
but still confused, why SAS treats &i as a character value(pp=&i) in the %do loop?
when we use do loop i.e. i=0 to 10, i was treated as a numeric value.

thx!
作者: shiyiming    时间: 2013-11-7 13:51
标题: Re: looking for help for a simple macro code
语法要求----%by 后面必须是整数。而你用的是小数,所以报错。
解决方法:将等差数列标准化成整数后,方可用%do %to %by。




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2