由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - SAS QUESTION:how to capture the last nonmissing observation?
相关主题
SAS quarter calculation questionAsk a SAS Base question?
[合集] SAS里如何实现LOCF(LAST OBS CARRIED FORWARD)?求问一道SAS adv 题
SAS base questionSAS应用问题
a SAS question in base 70[提问]怎样提取SAS Dateset的observation number?
SAS sampling的问题[SAS] data set options (obs=) in output tables
求教 SAS base 123 Q 16请教SAS BASE 70题里的第35题
A SAS problem【求助】Large Dataset Management
in =option的一道题怎么用SAS做加减乘除
相关话题的讨论汇总
话题: 78话题: 76话题: 33话题: value1话题: value2
进入Statistics版参与讨论
1 (共1页)
r********e
发帖数: 1686
1
RT
if I have a dataset as below:
id week value1
a 1 12
a 2 22
a 3 33
a 4 .
a 5 .
a 6 .
a 7 .
b 1 78
b 2 .
b 3 .
b 4 .
b 5 .
b 6 .
b 7 .
b 8 .
c 1 88
c 2 67
c 3 76
c 4 .
c 5 .
c 6 .
I need to capture the last missing value1 for each ID as value2 to achieve
the following dataset:
id week value1 value2
a 1 12 33
a 2 22 33
a 3 33 33
a 4 . 33
a 5 . 33
a 6 . 33
a 7 . 33
b 1 78 78
b 2 . 78
b 3 . 78
b 4 . 78
b 5 . 78
b 6 . 78
b 7 . 78
b 8 . 78
c 1 88 76
c 2 67 76
c 3 76 76
c 4 . 76
c 5 . 76
c 6 . 76
How can I do this? Thanks a lot!
r********e
发帖数: 1686
2
??
ziji ding
l*********s
发帖数: 5409
3
1)create a dataset holding the last nonmissing values for each group
2)do a sql join with original data set
k*******a
发帖数: 772
4
写了一个,不过有点繁
data a;
input id $ week value1;
datalines;
a 1 12
a 2 22
a 3 33
a 4 .
a 5 .
a 6 .
a 7 .
b 1 78
b 2 .
b 3 .
b 4 .
b 5 .
b 6 .
b 7 .
b 8 .
c 1 88
c 2 67
c 3 76
c 4 .
c 5 .
c 6 .
;
data b;
set a;
by id;
if value1 ne . then do
value2=value1;
retain value2;
end;
if last.id then output;
keep id value2;
data a;
merge a b;
by id;
proc print data=a;run;
R*********i
发帖数: 7643
5
It souds like a typical LOCF question:
proc sort data=a;
by id week;
data locf;
set a;
by id week;
where value1>.;
if last.id;
data out;
merge a locf (keep=id value1 rename=(value1=value2));
by id ;
proc print;
run;
l**********9
发帖数: 148
6

Nice~~~
set by id就可以了吧?不需要by week了吧?

【在 R*********i 的大作中提到】
: It souds like a typical LOCF question:
: proc sort data=a;
: by id week;
: data locf;
: set a;
: by id week;
: where value1>.;
: if last.id;
: data out;
: merge a locf (keep=id value1 rename=(value1=value2));

1 (共1页)
进入Statistics版参与讨论
相关主题
怎么用SAS做加减乘除SAS sampling的问题
how to generate a large SAS data set?求教 SAS base 123 Q 16
请问base(123题)的第16题A SAS problem
%do questionsin =option的一道题
SAS quarter calculation questionAsk a SAS Base question?
[合集] SAS里如何实现LOCF(LAST OBS CARRIED FORWARD)?求问一道SAS adv 题
SAS base questionSAS应用问题
a SAS question in base 70[提问]怎样提取SAS Dateset的observation number?
相关话题的讨论汇总
话题: 78话题: 76话题: 33话题: value1话题: value2