w*******n 发帖数: 469 | 1 data temp;
input x y $;
cards;
1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
9 I
10 J
;
run;
data wbh;
set temp(keep=x );
if x>2;
set temp(in=B);
run;
proc print;run; |
n****t 发帖数: 182 | 2 This code is the same as
data wbh;
set temp(in=B);
if x>2;
run;
Reason:
1. The variable x is already in temp, so temp(keep=x) does nothing.
2. No matter where you put the "set" statement, it always execute before the
"if" statement (as "if" is a loop over all rows, but set is not)
3. if you want to subset with "set", use "where" within set. |
d**s 发帖数: 1255 | 3 有意思。感觉是这样的
这里keep in 都是花招
if x > 2 决定了wbh 的 number of observation, say n
最后set temp(in=B), 读取了前面 n obs from temp |
w*******n 发帖数: 469 | 4 This output is obviously different. Have you run the coding?
the
【在 n****t 的大作中提到】 : This code is the same as : data wbh; : : : set temp(in=B); : if x>2; : run; : Reason: : 1. The variable x is already in temp, so temp(keep=x) does nothing. : 2. No matter where you put the "set" statement, it always execute before the
|
w*******n 发帖数: 469 | 5 Is there any logic for the output here? Hard to understand.
But I accept your interpretation.
【在 d**s 的大作中提到】 : 有意思。感觉是这样的 : 这里keep in 都是花招 : if x > 2 决定了wbh 的 number of observation, say n : 最后set temp(in=B), 读取了前面 n obs from temp
|
z**o 发帖数: 149 | 6 1. set temp(keep=x );
if x>2;
wbh has 8 obs,
x
3
4
5
6
7
8
9
10
2. set temp(in=B);
existed x replaced by new ones; since only 8 obs left,final wbh has 8 rows:
x y
1 A
2 B
3 C
4 D
5 E
6 F
7 G
8 H
【在 w*******n 的大作中提到】 : data temp; : input x y $; : cards; : 1 A : 2 B : 3 C : 4 D : 5 E : 6 F : 7 G
|
i******r 发帖数: 861 | 7 cool!!!
【在 z**o 的大作中提到】 : 1. set temp(keep=x ); : if x>2; : wbh has 8 obs, : x : 3 : 4 : 5 : 6 : 7 : 8
|