由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - sas coding help needed
相关主题
R question, calculate mean over some rowssas proc report的问题
How to run my R job as a batch job ?SAS问题
a R question请问R Code和 Matlab Code 思路是否近似?
新手问个R里vectorization的问题[急求助] survival analysis (SAS)
问个r问题请教一个SAS小问题:如何得到 one cumulative varialbe of character variable?
[合集] Need help on data manipulation, thanks a lot!更新一下Taste of R,再问两个R的问题。
SAS问题来了SAS question: count non-missing value for different variables
请教一个sas编程问题how to output cumulative percent to a dataset from Proc Freq?
相关话题的讨论汇总
话题: var2话题: var1话题: tem话题: sas话题: needed
进入Statistics版参与讨论
1 (共1页)
y**3
发帖数: 267
1
help needed from sas expert!
I have 2 variables in my sas data set-var1 var2. var2 only has value at the
first record.i need to compute the rest of var2 based on the ratios of two
records next to each other; for ex;
the 2nd row ; var22=(95/87)*85; then compute var23 based on the new number
and var12 and var13.
how to code this in sas efficiently? thanks
var1 var2
87 95
85
78
75
65
56
34
a******r
发帖数: 8
2
data new;
set old;
if (_n_ EQ 1) then tem=var2/var1;
retain tem;
var2=int(var1*tem);
keep var1 var2;
run;

the

【在 y**3 的大作中提到】
: help needed from sas expert!
: I have 2 variables in my sas data set-var1 var2. var2 only has value at the
: first record.i need to compute the rest of var2 based on the ratios of two
: records next to each other; for ex;
: the 2nd row ; var22=(95/87)*85; then compute var23 based on the new number
: and var12 and var13.
: how to code this in sas efficiently? thanks
: var1 var2
: 87 95
: 85

y**3
发帖数: 267
3
Thanks for the help!
But this way tem was set only var2/var1 at _n_=1. that is, tem is same for
all the rest of rows. But I need to re compute tem using the new var2 for
every rows. A do loop work?

【在 a******r 的大作中提到】
: data new;
: set old;
: if (_n_ EQ 1) then tem=var2/var1;
: retain tem;
: var2=int(var1*tem);
: keep var1 var2;
: run;
:
: the

a******r
发帖数: 8
4
According to your description, "tem=var2/var1" should have the same value
for all lines, right?

【在 y**3 的大作中提到】
: Thanks for the help!
: But this way tem was set only var2/var1 at _n_=1. that is, tem is same for
: all the rest of rows. But I need to re compute tem using the new var2 for
: every rows. A do loop work?

a******r
发帖数: 8
5
If you were not sure, try the following one.
data new;
set old;
if (_n_ EQ 1) then tem=var2/var1;
var2=var1*tem;
tem=var2/var1;
retain tem;
keep var1 var2;
run;
Be careful about the type of variables if your original types of var1 and
var2 are both integer.

【在 y**3 的大作中提到】
: Thanks for the help!
: But this way tem was set only var2/var1 at _n_=1. that is, tem is same for
: all the rest of rows. But I need to re compute tem using the new var2 for
: every rows. A do loop work?

y**3
发帖数: 267
6
Good job! thanks !!!!!!!!!!!!!

【在 a******r 的大作中提到】
: If you were not sure, try the following one.
: data new;
: set old;
: if (_n_ EQ 1) then tem=var2/var1;
: var2=var1*tem;
: tem=var2/var1;
: retain tem;
: keep var1 var2;
: run;
: Be careful about the type of variables if your original types of var1 and

a******c
发帖数: 291
7
Thanks a lot. I encountered a similar question half a year ago and used a
very clumsy method to resolve it by stacking computed rows one after another
. This is much more efficient.
a******c
发帖数: 291
8
Thanks a lot. I encountered a similar question half a year ago and used a
very clumsy method to resolve it by stacking computed rows one after another
. This is much more efficient.
1 (共1页)
进入Statistics版参与讨论
相关主题
how to output cumulative percent to a dataset from Proc Freq?问个r问题
[合集] how to calculate column sum not row sum in SAS? thanks a lo[合集] Need help on data manipulation, thanks a lot!
SAS question using PROC SQL 高手请进, 包子答谢SAS问题来了
请教sas高人(数据读入)请教一个sas编程问题
R question, calculate mean over some rowssas proc report的问题
How to run my R job as a batch job ?SAS问题
a R question请问R Code和 Matlab Code 思路是否近似?
新手问个R里vectorization的问题[急求助] survival analysis (SAS)
相关话题的讨论汇总
话题: var2话题: var1话题: tem话题: sas话题: needed