SAS中文论坛

标题: 数据结转 [打印本页]

作者: shiyiming    时间: 2011-9-9 13:50
标题: 数据结转
请问一下,如果一个变量中的值为空时,就结转同一个变量上一个值,以此类推,应该如何编程?
即 a
1



2
3
4
变为
a
1
1
1
1
2
3
4
作者: shiyiming    时间: 2011-9-9 15:53
标题: Re: 数据结转
[code:3o1kcmqo]data a;
input a;
cards;
1
.
.
.
2
3
3
.
3
.
4
.
.
;
data c;
set a ;
retain b;
if a>. then b=a;
run;

data d;
set a;
n=_n_;
if missing(a) then do;
   do until (not missing(a));
   n=n-1;
set a(keep=a) point=n; *second SET statement;
end;
end;
run;

data e;
   do until(last.a);
      set a;
      by a notsorted;
      if last.a and not missing(a) then do;
      b = a;
      end;  
      if missing(a) then do;
      a=b;
      end;  
      output;
   end;
run;
[/code:3o1kcmqo]
<!-- m --><a class="postlink" href="http://communities.sas.com/message/37471">http://communities.sas.com/message/37471</a><!-- m -->
作者: shiyiming    时间: 2011-9-10 09:54
标题: Re: 数据结转
[code:2tk1jckq]

data a;
input a;
cards;
1
&#46;
&#46;
&#46;
2
3
3
&#46;
3
&#46;
4
&#46;
&#46;
;
data c(drop=b impute);
set a ;
retain b;
if a&gt;&#46; then b=a;
if missing(a) and not missing(b) then do;
        impute=1;
        a=b;
end;
run;


proc print;
run;



[/code:2tk1jckq]
作者: shiyiming    时间: 2011-9-11 09:26
标题: Re: 数据结转
[code:1a8ylxqs]data result(drop=tmp);
        set a(rename=(a=tmp));
        retain a;
        if not missing(tmp) then a=tmp;
run;[/code:1a8ylxqs]




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2