Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...