| 
 | 
楼主
 
 
 楼主 |
发表于 2012-2-16 09:23:20
|
只看该作者
 
 
 
请高手过招
假设一个数据集有两个变量:child 和 parent 
DATA sample;  
INPUT child $ parent $; 
DATALINES;  
a b  
c b 
d c 
e g 
f e 
;  
run; 
 
例如:  
a 的 parent 是 b, 
c 的 parent 是 b, 
d 的 parent 是 c, 
e 的 parent 是 g, 
f 的 parent 是 e, 
等等。。。 
 
现在需要创建第三个变量highest_parent, 使得最终的数据集成为: 
DATA sample;  
INPUT child $ parent $ highest_parent $; 
DATALINES;  
a b b 
c b b 
d c b 
e g g 
f e g 
;  
run; 
 
a 的 parent 是 b,highest_parent 是 b 
c 的 parent 是 b,highest_parent 是 b 
d 的 parent 是 c,但 c 的 parent 是 b, 所以highest_parent 是 b, 
相似的 
e 的 parent 是 g,highest_parent 是 g 
f 的 parent 是 e,highest_parent 是 g 
等等。。。 
如何用SAS实现? |   
 
 
 
 |