从 SAS 中的多个数据集中获取和减去观察总数
Obtain and minus total number of observation from multiple datasets in SAS
在特定条件下,我必须从大型数据集中准备 5 tables。
5 tables 的 obs 总数为 1000。
我准备了前四个table。
对于第五个table,我有麻烦select obs (1000 minus sum(table 1 to 4)).
我可以手动对 odsnumber 求和,但它会影响效率,因为这必须定期完成。
谁能指导我如何改进这些脚本?
Proc sql;
select nobs
into: odsnumber trimmed
from sashelp.vtable
where libname='work' and memname in ('table1' 'table2' 'table3' 'table4')
;quit;
data table5;
set source;
if 1<=_N_<=sum(1000,manual calculation of nobs from 4 tables);
run;
计算 SQL 中四个 NOBS 的总和,您将不必手动计算它。
在 SQL 中,我更喜欢使用 DICTIONARY
表而不是 SASHELP.V*
视图。当需要从 DATA
或 PROC
步骤访问元数据时使用视图。
从元数据字典表中查询时,libname
和 memname
值始终为大写。
示例:
data table1; do row = 1 to 10; output; end;
data table2; do row = 1 to 100; output; end;
data table3; do row = 1 to 100; output; end;
data table4; do row = 1 to 40 ; output; end;
data source; do row = 1 to 2500; output; end;
proc sql NOPRINT;
select SUM(nobs)
into: NOBS_OF_4_TABLES trimmed
from DICTIONARY.TABLES
where libname='WORK'
and memname in ('TABLE1' 'TABLE2' 'TABLE3' 'TABLE4')
;
%put NOTE: &=NOBS_OF_4_TABLES; %* Check log to see value computed;
data table5;
set source;
if _N_ > 1000 - &NOBS_OF_4_TABLES then stop;
run;
在特定条件下,我必须从大型数据集中准备 5 tables。 5 tables 的 obs 总数为 1000。 我准备了前四个table。 对于第五个table,我有麻烦select obs (1000 minus sum(table 1 to 4)).
我可以手动对 odsnumber 求和,但它会影响效率,因为这必须定期完成。 谁能指导我如何改进这些脚本?
Proc sql;
select nobs
into: odsnumber trimmed
from sashelp.vtable
where libname='work' and memname in ('table1' 'table2' 'table3' 'table4')
;quit;
data table5;
set source;
if 1<=_N_<=sum(1000,manual calculation of nobs from 4 tables);
run;
计算 SQL 中四个 NOBS 的总和,您将不必手动计算它。
在 SQL 中,我更喜欢使用 DICTIONARY
表而不是 SASHELP.V*
视图。当需要从 DATA
或 PROC
步骤访问元数据时使用视图。
libname
和 memname
值始终为大写。
示例:
data table1; do row = 1 to 10; output; end;
data table2; do row = 1 to 100; output; end;
data table3; do row = 1 to 100; output; end;
data table4; do row = 1 to 40 ; output; end;
data source; do row = 1 to 2500; output; end;
proc sql NOPRINT;
select SUM(nobs)
into: NOBS_OF_4_TABLES trimmed
from DICTIONARY.TABLES
where libname='WORK'
and memname in ('TABLE1' 'TABLE2' 'TABLE3' 'TABLE4')
;
%put NOTE: &=NOBS_OF_4_TABLES; %* Check log to see value computed;
data table5;
set source;
if _N_ > 1000 - &NOBS_OF_4_TABLES then stop;
run;