从数据库 (SAS) 中删除以值列表开头的所有观察值
Delete all observations starting with a list of values from database (SAS)
我正在尝试找到执行此操作的优化方法:
我想从字符变量中删除所有以不同的可能字符串开头的观察结果,例如:
"小计" "包括:"
因此,如果它以这些值中的任何一个(或我没有在这里写的许多其他值)开头,则将它们从数据集中删除。
最好的解决方案是一个包含所有值的宏变量,但我不知道如何处理它。 (%let list = Subtotal Including: but counts as variables while they are values)
我这样做了:
数据一个;设置 b ;
if findw(product,"小计") then delete ;
if findw(product,"Including:") 然后删除;
...
...
非常感谢任何建议!谢谢
首先弄清楚你想要什么SAS代码。那么你就可以开始为如何使用宏逻辑或者宏变量发愁了。
是否只排除以值开头的字符串?
data want ;
set have ;
where product not in: ("Subtotal" "Including");
run;
或者您想根据字符串变量中的第一个“单词”进行子集化?
where scan(product,1) not in ("Subtotal" "Including");
或者不区分大小写?
where lowcase(scan(product,1)) not in ("subtotal" "including");
现在,如果值列表足够小(小于 64K 字节),那么您可以将列表放入宏变量中。
%let list="Subtotal" "Including";
然后再使用宏变量生成WHERE语句。
where product not in: (&list);
您甚至可以从前缀值的数据集中生成宏变量。
proc sql noprint;
select quote(trim(prefix)) into :list separated by ' '
from prefixes
;
quit;
我正在尝试找到执行此操作的优化方法:
我想从字符变量中删除所有以不同的可能字符串开头的观察结果,例如:
"小计" "包括:" 因此,如果它以这些值中的任何一个(或我没有在这里写的许多其他值)开头,则将它们从数据集中删除。
最好的解决方案是一个包含所有值的宏变量,但我不知道如何处理它。 (%let list = Subtotal Including: but counts as variables while they are values)
我这样做了:
数据一个;设置 b ; if findw(product,"小计") then delete ; if findw(product,"Including:") 然后删除; ... ...
非常感谢任何建议!谢谢
首先弄清楚你想要什么SAS代码。那么你就可以开始为如何使用宏逻辑或者宏变量发愁了。
是否只排除以值开头的字符串?
data want ;
set have ;
where product not in: ("Subtotal" "Including");
run;
或者您想根据字符串变量中的第一个“单词”进行子集化?
where scan(product,1) not in ("Subtotal" "Including");
或者不区分大小写?
where lowcase(scan(product,1)) not in ("subtotal" "including");
现在,如果值列表足够小(小于 64K 字节),那么您可以将列表放入宏变量中。
%let list="Subtotal" "Including";
然后再使用宏变量生成WHERE语句。
where product not in: (&list);
您甚至可以从前缀值的数据集中生成宏变量。
proc sql noprint;
select quote(trim(prefix)) into :list separated by ' '
from prefixes
;
quit;