将 first.variable 和 last.variables 与累加器变量一起使用 [英] Using first.variable and last.variables with accumulator variables
问题描述
我想了解这个程序的作用.
I am trying to understand what this program does.
data a;
set b (keep=c d);
by c;
if first.c then e=0;
e+d;
if last.c;
run;
让我困惑的是以下内容.
What confuses me is the following.
1)、当没有THEN语句时,IF语句有什么作用?
1), When there is not THEN statements, what does and IF statement do?
2), 当没有被评估的值时,IF 语句有什么作用?(为什么不说 if first.c =1 之类的?)
2), When there is no value evalueated, what does an IF statement do ? (why would it not say something like if first.c =1 ?)
3),我的理解是e是一个从0开始的累加器变量,d是通过迭代相加的.但出于某种原因,e 代表 c 的所有值的总和,而不是 d,即使我们添加了 d.
3), My understanding is that e is an accumulator variable starting from 0, and d is added by iteration. But for some reason e represents the total for all values of c, not d even though we are adding d.
我认为前两个问题将回答我的问题 3,但我非常感谢您的帮助.
I am thinking that the first two questions will answer my question 3, but I would really appreciate your help.
推荐答案
在 SAS 中有两种不同的 if
语句 - if-then-else
和 subsetting 如果
.它们具有相似的语法,但它们做不同的事情.您的代码中各有一个.
In SAS there are two different if
statements - if-then-else
and subsetting if
. They have similar syntax but they do different things. You have one of each in your code.
这就是 文档:
子集 IF 语句等效于这个 IF-THEN 语句:
The subsetting IF statement is equivalent to this IF-THEN statement:
如果不是(表达式)则删除;
if not (expression) then delete;
这篇关于将 first.variable 和 last.variables 与累加器变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!