由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - sas 求助,急
相关主题
SAS help请教:三道SAS BASE题
Use SAS to fill in missing values?请教sas code问题
菜鸟的SAS问题,向高手求助再问个问题,如何从dataset里删除一个data pattern?
填充缺失值 问题请教 (SAS, R, 所用软件不限)Mission Improbable: A Concise and Precise Definition of P-Value
help with a sas codeCollapsing for GSEA
工作中SAS问题 —另一个问题请教!SAS新手请教一个关于数据导出的问题
请教一个 SAS macro被redundancy 了面临两个选择
How to combine overlapped data想对很多variables做pairwise的比较
相关话题的讨论汇总
话题: 12话题: 10话题: lag话题: howmany话题: since
进入Statistics版参与讨论
1 (共1页)
t*********e
发帖数: 143
1
现有一个table. sample结构如下
a b c d
10 1 2 15
10 2 2 14
10 3 2 24
10 4 2 35
12 1 3 11
12 2 3 148
12 3 3 27
12 4 3 19
12 5 3 8
25 1 7 4
25 2 7 8

table 以a,b ascending为index.
现在想要达成如下结果
对每一个a,b组合值,根据c和d的值生成一个step方程的值.
e=0 if b<=c
e=2+18*(lag of d by the value of c-5)^2
比如。
for a=10, b=1, since b=1 a=10, b=2, since b=c=2, then e=0
a=10, b=3, since b=3 > c=2, then e=2+18*(15-5)^2=1802, 15是d lag 2生
成的
a=10, b=4, since b=4 > c=2, then e=2+18*(14-5)^2=
a=12, b=1, since b=1 a=12, b=2, since b=2 请问有没有什么简便的方法达到想要的结果,对我来说最大的问题是lag的处理,它是depend on c的
如果解决大包子送上
D******n
发帖数: 2836
2
use R

【在 t*********e 的大作中提到】
: 现有一个table. sample结构如下
: a b c d
: 10 1 2 15
: 10 2 2 14
: 10 3 2 24
: 10 4 2 35
: 12 1 3 11
: 12 2 3 148
: 12 3 3 27
: 12 4 3 19

s******y
发帖数: 352
3
data have;
input a b c d;
cards;
10 1 2 15
10 2 2 14
10 3 2 24
10 4 2 35
12 1 3 11
12 2 3 148
12 3 3 27
12 4 3 19
12 5 3 8
25 1 7 4
25 2 7 8
;
run;
data want;
call missing(of lagd);
set have;
howmany=c;
if b<=c then e=0;
else if b>c and _n_-howmany>0 then do back=_n_-1 by -1 while(howmany>0) ;
set have(rename=(d=lagd)keep=d) point=back ;
howmany=sum(howmany,-1);
exp=cats('2+18*(',lagd,'-5)^2');
e=2+18*(lagd-5)**2;
end;
drop lagd howmany;
run;

【在 t*********e 的大作中提到】
: 现有一个table. sample结构如下
: a b c d
: 10 1 2 15
: 10 2 2 14
: 10 3 2 24
: 10 4 2 35
: 12 1 3 11
: 12 2 3 148
: 12 3 3 27
: 12 4 3 19

D******n
发帖数: 2836
4
can be more concise
data a2;
set a1;
if b<=c then e=0;
else if _n_-c>0 then do;
back = _n_ - c;
set a1(rename=(d=lag_d) keep=d) point=back;
e = 2+18*(lag_d-5)**2;
end;
drop lag_d;
run;

proc print;run;

【在 s******y 的大作中提到】
: data have;
: input a b c d;
: cards;
: 10 1 2 15
: 10 2 2 14
: 10 3 2 24
: 10 4 2 35
: 12 1 3 11
: 12 2 3 148
: 12 3 3 27

s******y
发帖数: 352
5
Very good point. the loop is redundant. we just need to rewind back C times,
no need to keep track the current position.
I wouldn't leave the call missing off. because the lag_d is sort of self
retained. most of time you don't want that happens.

【在 D******n 的大作中提到】
: can be more concise
: data a2;
: set a1;
: if b<=c then e=0;
: else if _n_-c>0 then do;
: back = _n_ - c;
: set a1(rename=(d=lag_d) keep=d) point=back;
: e = 2+18*(lag_d-5)**2;
: end;
: drop lag_d;

S******y
发帖数: 1123
6
#Python 2.6
in_file = r'C:\abcd.txt'
f = open(in_file, 'r')
f.next() #skip header row
ls_d = []
for line in f:
a,b,c,d = line.split()
if int(b) <= int(c): e = 0
else: e = 2 + 18 * (ls_d[-int(c)]-5) * (ls_d[-int(c)]-5)
print a, b, c, d, e
ls_d.append(int(d))
#---------------------------------------------------#
1 (共1页)
进入Statistics版参与讨论
相关主题
想对很多variables做pairwise的比较help with a sas code
请帮忙看看这份简历怎么样,怎么进一步修改。多谢!工作中SAS问题 —另一个问题请教!
R environment 问题请教一个 SAS macro
Discover Financial - Sr. Associate in Marketing AnalyticsHow to combine overlapped data
SAS help请教:三道SAS BASE题
Use SAS to fill in missing values?请教sas code问题
菜鸟的SAS问题,向高手求助再问个问题,如何从dataset里删除一个data pattern?
填充缺失值 问题请教 (SAS, R, 所用软件不限)Mission Improbable: A Concise and Precise Definition of P-Value
相关话题的讨论汇总
话题: 12话题: 10话题: lag话题: howmany话题: since