w*****y 发帖数: 130 | 1 比方说,
var1 var2 var3
a miss 1.1
a 5 miss
a 6 miss
b 5 0
b 5 0
b 7 miss
.
.
.
如果变量3大于零(1.1),那么所在的组所有观察值得变量3赋值都等于1.1
谢谢! |
h******e 发帖数: 1791 | |
w*****y 发帖数: 130 | 3
by var1,
thanks
【在 h******e 的大作中提到】 : 这个“组”是如何定义的?
|
h******e 发帖数: 1791 | 4 一个繁琐的方法:
data test;
input var1 $ var2 var3;
datalines;
a . 1.1
a 5 .
a 6 .
b 5 0
b 5 0
b 7 .
;
run;
data t1;
set test;
by var1;
if first.var1 then var4 = 1;
else if first.var1 = 0 and last.var1 = 0 then var4 = 2;
else if last.var1 then var4 = 3;
run;
proc transpose data = t1 out = t2;
by var1 var2;
id var4;
var var3;
run;
data t3;
set t2;
if _1 > 0 or _2 >0 or _3 >0 then do;
_1 = 1.1;
_2 = 1.1;
_3 |
T*******I 发帖数: 5138 | 5 You are a crazy statistician. According to your statement, you cannot
do that. In the Group a, you have two missing values, which means you don't
know them. But you want to change their values to be 1.1, by which you
definitely know them. Crazy!
【在 w*****y 的大作中提到】 : : by var1, : thanks
|
R******d 发帖数: 1436 | 6 不知道我理解对了不
data test;
input var1 $ var2 var3;
datalines;
a . 1.1
a 5 .
a 6 .
b 5 0
b 5 0
b 7 .
;
run;
proc sql noprint;select distinct var1 into:vars separated by ' ' from test;quit;
proc sql noprint;select count(distinct var1) into:nvar from test; quit;
%macro test;
%do i=1 %to &nvar;
proc sql noprint;
create table tmp as
select *,max(var3>0) as index,max(var3) as max from test where var1="%qscan(&vars,&i,' ')";
quit;
proc append base |
R******d 发帖数: 1436 | 7 回头看一下,前面写得有点脱裤子放屁
data test;
input var1 $ var2 var3;
datalines;
a . 1.1
a 5 .
a 6 .
b 5 0
b 5 0
b 7 .
;
run;
proc sql noprint;
create table result as
select *, max(var3) as max, max(var3)>0 as index from test group by var1;
quit;
data result;
set result;
if index=1 then var3=max;
run; |
s******r 发帖数: 1524 | 8 proc sort data=test;by var1 descending var3 ;run;
data t1;
set test;
by var1;
if first.var1 then do;
if var3>0 then varx=var3;else varx=.;
end;
var4=max(var3,varx);
retain varx;
drop varx;
run;
【在 w*****y 的大作中提到】 : 比方说, : var1 var2 var3 : a miss 1.1 : a 5 miss : a 6 miss : b 5 0 : b 5 0 : b 7 miss : . : .
|