l*******1 发帖数: 6 | 1 The data has so many continuous missing values.
Based on Time variable and value variable, how to generate flag variable
according to the following criteria?
For no missing values, flag=0;
first missing value flag=-1
middle missing value flag=1
last missing value flag=2
Time value flag
1 56 0
2 34 0
3 26 0
4 19 0
5 70 0
6 66 0
7 . -1
8 . 1
9 . 1
10 . 2
11 35 0
12 23 0
13 90 0
14 82 0
15 44 0
16 . -1
17 . 1
18 . 1
19 . 1
20 . 1
21 . 2
22 34 0
23 45 0
24 65 0
25 50 0
26 100 0
27 39 0
28 .-1
29 . 1
30 . 1
31 . 1
32 . 1
33 . 1
34 . 2
35 67 0
36 78 0
Great Thanks | k*******a 发帖数: 772 | 2 假设你的data是a
data b;
set a;
if value=. then flag=1;
else flag=0;
run;
data c;
set b;
by flag notsorted;
if flag=1 then do;
if first.flag then flag=-1;
else if last.flag then flag=2;
end;
run;
这里的问题就是,如果连续missing只有1个的话,这个程序给的是2,如果希望其他数
值,可以相应调整 | l*******1 发帖数: 6 | 3
Actually for 1 missing, I need to replace it with its previous value and
following value, For continuous 2 missing, i will replace them with previous
2 and following 2 values, for continuous 3 missing, i will replace them
with previous 3 and following 3 values.(If these missing are not in the end)
,so for the remaining data, It will have at least 4 missing values.
Would you add these code before that you provide to get rid of <=3 missing?
Thank you very much.
【在 k*******a 的大作中提到】 : 假设你的data是a : data b; : set a; : if value=. then flag=1; : else flag=0; : run; : data c; : set b; : by flag notsorted; : if flag=1 then do;
|
|