data test;
input num;
datalines;
2
10
20
;
data dest(drop=i n);
set test;
retain n; /*store the value of num for last observation*/
if _n_=1 then do;
n=num;
output;
return;
end;
else do;
do i=1 to num;
output;
end;
n=num;
end;
run;
data test;
input num;
datalines;
2
10
20
;
data dest(drop=i num);
set test end=lstob;
retain n; /*store the value of num for last observation*/
if _n_=1 then do;
n=num;
output;
return;
end;
else do;
do i=1 to num;
output;
end;
n=num;
output;
end;
run;
data final(keep=x y);
set ahuige end=end;
if not end then
do;
p=_n_+1;
set ahuige(keep=x rename=(x=rptn)) point=p;
do i=1 to rptn+1;
output;
end;
end;
else output;
run;[/code:w515fxmd]好像l746.....这位仁兄的程序对多于一个变量的数据集会有硬伤作者: shiyiming 时间: 2009-6-17 20:40 标题: Re: 急:请教:如何在两条记录之间重复添加上一条记录? 主要是利用原数据集生成新数据,原数据只读了一遍,,应该对原数据没有影响。
你的意思是??
[quote="ahuige":3hbcduq8][code:3hbcduq8]data ahuige;
input x y;
cards;
1 5
4 6
5 7
;
run;
data final(keep=x y);
set ahuige end=end;
if not end then
do;
p=_n_+1;
set ahuige(keep=x rename=(x=rptn)) point=p;
do i=1 to rptn+1;
output;
end;
end;
else output;
run;[/code:3hbcduq8]好像l746.....这位仁兄的程序对多于一个变量的数据集会有硬伤[/quote:3hbcduq8]作者: shiyiming 时间: 2009-6-17 21:38 标题: Re: 急:请教:如何在两条记录之间重复添加上一条记录? 硬伤不是说你把原来的数据搞坏了,是说你重复的东西不对。你的程序只对只有一个变量的数据有效,多于一个变量的结果就不对了。作者: shiyiming 时间: 2009-6-17 22:00 标题: Re: 急:请教:如何在两条记录之间重复添加上一条记录? 呵呵,明白了。变量多的话,可能就会比较麻烦。