如何在SAS工作表中上下移动行
我在SAS中有一个工作表,我想将表的最后一行移到最后第二行。有没有可能通过编程实现这一点?如果是,怎么做如何在SAS工作表中上下移动行,sas,Sas,我在SAS中有一个工作表,我想将表的最后一行移到最后第二行。有没有可能通过编程实现这一点?如果是,怎么做 提前谢谢我想这就是你想要的 data class; set sashelp.class nobs=n; if _N_ = n-1 then delete; run; 如果数据集中没有id变量,可以先创建一个。在以下情况下,您的数据集称为have: 然后,当id变量等于maxid时,您可以从id变量中减去一,当它等于maxid减一时,您可以添加一。最后,按id对新数据集进行排序。
提前谢谢我想这就是你想要的
data class;
set sashelp.class nobs=n;
if _N_ = n-1 then delete;
run;
如果数据集中没有id变量,可以先创建一个。在以下情况下,您的数据集称为have:
然后,当id变量等于maxid时,您可以从id变量中减去一,当它等于maxid减一时,您可以添加一。最后,按id对新数据集进行排序。这将切换最后两行的位置
proc sql;
create table want as
select
case when id=max(id) then id-1
when id=max(id)-1 then id+1
else id end as id,
*
from temp
order by id;
quit;
如果您的原始数据集已经有一个名为id的变量,只需将上面代码中的所有id替换为新变量的名称,它就会执行您想要的操作。使用设置选项POINT=根据序列位置从特定行读取
data have;
do row = 1 to 10;
output;
end;
run;
data want;
do row_index = 1 to row_count-2, row_count, row_count-1;
set have nobs=row_count point=row_index;
output;
end;
STOP;
run;
还有一个是使用MODIFY
data class;
_obs_+1;
set sashelp.class;
run;
data class;
do point=nobs-2;
modify class point=point nobs=nobs;
remove;
output;
end;
stop;
run;
proc print;
run;
那么,你想对最后一排做什么?删除它?通常,SAS不建议按索引访问列和行。如果您需要索引功能,IML确实提供了这一功能。否则,通常会有其他方法来实现您所需要的,尽管与您预期的略有不同。do row_index=1到row_count-2,row_count,row_count-1;好电话@汤姆,换了
data class;
_obs_+1;
set sashelp.class;
run;
data class;
do point=nobs-2;
modify class point=point nobs=nobs;
remove;
output;
end;
stop;
run;
proc print;
run;