如何"add half of the minimum positive value (among all) to all the response value" 记录前
How to "add half of the minimum positive value (among all) to all the response value" before taking log
我的一些响应变量的值为零。我想找到正最小值是多少,将其除以 2,然后在取对数之前将该值加到所有原始值上。请帮我做这件事。这是我当前的代码,但似乎不正确。
data dat; set dat;
lvar = log(var + (min(var) / 2));
run;
这里是一些示例数据
data dat;
cards;
a var
1 0
2 5
3 6
4 7
5 10
6 2
7 0
8 4
9 0
;
感谢任何建议
在 DATA 步中,您可以使用双 DoW 循环执行此操作。您不依赖隐式的 DATA 步循环,而是使循环显式。在一个 DATA 步中,您读取数据一次以找到最小值,然后读取第二次以计算 lvar 和输出记录。
类似于:
data want;
*loop through all records, to find the minimum;
do until(eof);
set dat end=eof;
if var ne 0 then minvar=min(var,minvar);
end;
eof=0; *reset eof flag;
*loop through the records again, computing lvar;
*and outputting each record;
do until(eof);
set dat end=eof;
lvar=log(var+minvar);
put (_all_)(=);
output;
end;
run;
我的一些响应变量的值为零。我想找到正最小值是多少,将其除以 2,然后在取对数之前将该值加到所有原始值上。请帮我做这件事。这是我当前的代码,但似乎不正确。
data dat; set dat;
lvar = log(var + (min(var) / 2));
run;
这里是一些示例数据
data dat;
cards;
a var
1 0
2 5
3 6
4 7
5 10
6 2
7 0
8 4
9 0
;
感谢任何建议
在 DATA 步中,您可以使用双 DoW 循环执行此操作。您不依赖隐式的 DATA 步循环,而是使循环显式。在一个 DATA 步中,您读取数据一次以找到最小值,然后读取第二次以计算 lvar 和输出记录。
类似于:
data want;
*loop through all records, to find the minimum;
do until(eof);
set dat end=eof;
if var ne 0 then minvar=min(var,minvar);
end;
eof=0; *reset eof flag;
*loop through the records again, computing lvar;
*and outputting each record;
do until(eof);
set dat end=eof;
lvar=log(var+minvar);
put (_all_)(=);
output;
end;
run;