从sas中的数据集中删除N个最高值
我有一堆不同长度的sas数据集,我需要用一个变量值修剪第n个最高值和最低值 当我需要修剪最高和最低的部分时,我这样做了从sas中的数据集中删除N个最高值,sas,Sas,我有一堆不同长度的sas数据集,我需要用一个变量值修剪第n个最高值和最低值 当我需要修剪最高和最低的部分时,我这样做了 DATA VDBP273_first_night_Systolic; SET VDBP273_first_night end=eof; IF _N_ =1 then delete; if eof then delete; run; 而且效果很好 现在我需要做更多类似的事情 PROC SORT DATA=f
DATA VDBP273_first_night_Systolic;
SET VDBP273_first_night end=eof;
IF _N_ =1 then delete;
if eof then delete;
run;
而且效果很好
现在我需要做更多类似的事情
PROC SORT DATA=foo OUT=foo_sorted;
BY bar;
run;
DATA foo_out;
SET foo_sorted end=eof;
IF _N_ <= 5 then delete;
if eof *OR THE 4 right before it* then delete;
run;
PROC SORT DATA=foo OUT=foo_sorted;
酒吧;
跑
数据输出;
设置foo_sorted end=eof;
如果_N_因为您正在对数据进行预排序,然后试图消除前N个和后N个记录,那么您可以使用OBS=和FIRSTOBS=数据集选项轻松解决问题
proc sql noprint;
select count(*) -4 into:counter from sashelp.class ;
quit;
proc sort data=sashelp.class out=have;by height;run;
proc print data=have;run;
data want;
set have(firstobs=6 obs=&counter);
run;
proc print data=want;run;
由于您正在对数据进行预排序,然后试图消除前n个和后n个记录,因此可以使用OBS=和FIRSTOBS=数据集选项轻松解决问题
proc sql noprint;
select count(*) -4 into:counter from sashelp.class ;
quit;
proc sort data=sashelp.class out=have;by height;run;
proc print data=have;run;
data want;
set have(firstobs=6 obs=&counter);
run;
proc print data=want;run;
由于您正在对数据进行预排序,然后试图消除前n个和后n个记录,因此可以使用OBS=和FIRSTOBS=数据集选项轻松解决问题
proc sql noprint;
select count(*) -4 into:counter from sashelp.class ;
quit;
proc sort data=sashelp.class out=have;by height;run;
proc print data=have;run;
data want;
set have(firstobs=6 obs=&counter);
run;
proc print data=want;run;
由于您正在对数据进行预排序,然后试图消除前n个和后n个记录,因此可以使用OBS=和FIRSTOBS=数据集选项轻松解决问题
proc sql noprint;
select count(*) -4 into:counter from sashelp.class ;
quit;
proc sort data=sashelp.class out=have;by height;run;
proc print data=have;run;
data want;
set have(firstobs=6 obs=&counter);
run;
proc print data=want;run;
您可以使用nobs=
dataset选项来存储观察总数,这意味着您可以执行类似于代码的操作来排除前/后n个记录。
我建议将要排除的记录数放在宏变量中,这样比硬编码更容易读取和更改
%let excl = 6;
data want;
set sashelp.class nobs=numobs;
if &excl.< _n_ <=(numobs-&excl.);
run;
%let exc=6;
数据需求;
设置sashelp.class nobs=numobs;
如果&excl.<\u n\p>您可以使用nobs=
dataset选项来存储观察总数,这意味着您可以执行类似于代码的操作来排除顶部/底部的n条记录。
我建议将要排除的记录数放在宏变量中,这样比硬编码更容易读取和更改
%let excl = 6;
data want;
set sashelp.class nobs=numobs;
if &excl.< _n_ <=(numobs-&excl.);
run;
%let exc=6;
数据需求;
设置sashelp.class nobs=numobs;
如果&excl.<\u n\p>您可以使用nobs=
dataset选项来存储观察总数,这意味着您可以执行类似于代码的操作来排除顶部/底部的n条记录。
我建议将要排除的记录数放在宏变量中,这样比硬编码更容易读取和更改
%let excl = 6;
data want;
set sashelp.class nobs=numobs;
if &excl.< _n_ <=(numobs-&excl.);
run;
%let exc=6;
数据需求;
设置sashelp.class nobs=numobs;
如果&excl.<\u n\p>您可以使用nobs=
dataset选项来存储观察总数,这意味着您可以执行类似于代码的操作来排除顶部/底部的n条记录。
我建议将要排除的记录数放在宏变量中,这样比硬编码更容易读取和更改
%let excl = 6;
data want;
set sashelp.class nobs=numobs;
if &excl.< _n_ <=(numobs-&excl.);
run;
%let exc=6;
数据需求;
设置sashelp.class nobs=numobs;
如果&excl.<\u n\p>或只需执行之前完成的相同步骤,则将降序添加到proc sort变量中
proc sort data=have out=want; by var1 descending; run;
或者简单地执行之前完成的相同步骤,将降序添加到proc sort变量
proc sort data=have out=want; by var1 descending; run;
或者简单地执行之前完成的相同步骤,将降序添加到proc sort变量
proc sort data=have out=want; by var1 descending; run;
或者简单地执行之前完成的相同步骤,将降序添加到proc sort变量
proc sort data=have out=want; by var1 descending; run;