gpt4 book ai didi

sas - 遍历名称时有没有办法跳过丢失的数据集?

转载 作者:行者123 更新时间:2023-12-02 06:26:53 25 4
gpt4 key购买 nike

我在 SAS 中有一些数据集,我试图将它们整理成一个更大的数据集,稍后我将对其进行过滤。它们都被称为 table_201802。我的问题是缺少几个月(即存在 table201802table201804 及以上,但不存在 table201803

我对 SAS 还不够陌生,但到目前为止我尝试的是创建一个名为 output testing 的新数据集并运行一个宏循环迭代名称(它们来自 201802201903,它们是月度数据,因此从 812 到 900 的任何数据都不存在)。

data output_testing;
set
%do i=802 %to 812;
LIBRARY.table_201&i
%end;
;
run;
%mend append;

我希望代码忽略丢失的表,只查找确实存在的表,然后将它们附加到新的 output_testing 表中。

最佳答案

如果表名前缀不同,并且您确信表中的数据结构是一致的(变量名称、类型和长度相同),则可以使用表名前缀列表(: )

对于特定的已知范围的表名,您还可以使用编号范围列表 (-) 选项卡

data have190101 have190102 have190103;
x =1;
run;

data want_version1_stack; /* any table name that starts with have */
set have:;
run;

data want_version1b_stack; /* 2019 and 2020 */
set have19: have20:;
run;

options nodsnferr;
data want_version2_stack; /* any table names in the iterated numeric range */
set have190101-have191231;
run;
options dsnferr;

来自 helps

Using Data Set Lists with SET
You can use data set lists with the SETstatement. Data set lists provide a quick way to reference existinggroups of data sets. These data set lists must either be name prefixlists or numbered range lists.

Name prefix lists refer to all datasets that begin with a specified character string. For example, setSALES1:; tells SAS to read all data sets that start with "SALES1" suchas SALES1, SALES10, SALES11, and SALES12. >

Numbered range listsrequire you to have a series of data sets with the same name, exceptfor the last character or characters, which are consecutive numbers.In a numbered range list, you can begin with any number and end withany number. For example, these lists refer to the same data sets:

  • sales1 sales2 sales3 sales4
  • sales1-sales4

关于sas - 遍历名称时有没有办法跳过丢失的数据集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56931747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com