英文:
%by macro statement within %do loop not working as I would need
问题
我在SAS宏中的%do循环内使用%by语句遇到了问题:当运行这段代码时,循环并没有在1处停止,而是一直进行到0。
work.TO_current表确实包含了以_0索引的变量,但这段代码的整个目的应该是防止对它们进行重命名。
我知道这个问题对于更有经验的SAS用户来说可能很傻,但我无法理解它...先在这里感谢您!
英文:
I have a problem with a %by statement within a %do-loop inside a SAS macro: when I run this piece of code
%let Today = 22;
%let last_day_prev = 31;
%MACRO Rename;
data work.TO_current_2;
set work.TO_current;
%Do curr_day= &Today. %TO curr_day = 1 %BY -1;
%let eval_day = %eval(&curr_day +(&last_day_prev));
rename Total_out_bal_odd_&curr_day. = total_out_bal_odd_&eval_day.;
rename Balance_&curr_day. = Balance_&eval_day.;
rename Team_&curr_day. = team_&eval_day.;
rename Bucket_odd_&curr_day. = Bucket_odd_&eval_day.;
rename Bucket_assig_odd_&curr_day. = Bucket_assig_odd_&eval_day.;
rename DPD_NDD_&curr_day. = DPD_NDD_&eval_day.;
%END;
run;
%MEND;
%rename;
the loop does not stop (as I would expect) at 1, but goes beyond until 0.
The work.TO_current table does indeed contain variables indexed to _0, but the whole purpose of this code should be to prevent them from being renamed.
I know this question is probably silly for more experienced SAS users, but I can't wrap my head around it... thanks in advance!
答案1
得分: 0
你需要指定一个整数(或生成整数的宏表达式)作为 %TO
参数的最终宏变量迭代值。
将您的语句从
更改为
英文:
You are expected to specifiy an integer (or a macro expression that generates an integer) to use as the final macro-variable iteration value for the %TO
argument.
Change your statement from
%DO curr_day=&today. %TO curr_day = 1 %BY -1;
to
%DO curr_day=&today. %TO 1 %BY -1;
答案2
得分: 0
SAS会将布尔表达式评估为TRUE时的1,FALSE时的0。
因为数字1
不等于字符串curr_day
,所以您告诉%DO循环目标值为0。如果您希望目标值为1,只需直接这样说:
%DO curr_day=&today. %TO 1 %BY -1;
英文:
SAS evaluates boolean expressions to 1 for TRUE and 0 for FALSE.
Since the digit 1
does not equal the string curr_day
you told the %DO loop that the target value was 0. If you want the target value to be 1 just say that directly.
%DO curr_day=&today. %TO 1 %BY -1;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论