Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

sas - 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), When there is not THEN statements, what does and IF statement do?

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), 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.

I am thinking that the first two questions will answer my question 3, but I would really appreciate your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

This is how it's explained in the documentation:

The subsetting IF statement is equivalent to this IF-THEN statement:

if not (expression) then delete;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...