arrays - SAS中多列的哈希表搜索
问题描述
我有一个大约 40M 行的数据。有 50 列我想从中提取字符串。我已经使用带有数组的普通数据步骤来执行任务,但是完成提取需要 2 个多小时。
我知道如何通过首先指定查找表来使用 SAS 中的哈希表进行简单的连接或子集化。但是,我更喜欢在这里使用正则表达式进行提取。当前提取使用如下代码。
如何在没有查找表的情况下在 SAS 中的这 50 列中进行哈希表搜索?
data want;
set have;
array cols {*} $ col1 - col50;
do i = 1 to dim(cols)
if prxmatch('/F[0-9].*[123]/', cols[i])
then output;
end;
run;
解决方案
正则表达式模式中的分组将设置检索匹配项所需的条件PRXPOSN
。匹配可以存储在数据集处理结束时输出的散列中。
data _null_;
set have end=done;
array cols {*} $ col1 - col50;
rxid = prxparse('/(F[0-9].*[123])/');
if _n_ = 1 then do;
length match $200;
declare hash matches();
matches.defineKey(match);
matches.defineDone();
end;
do i = 1 to dim(cols)
if prxmatch(rxid, cols[i]) then do;
match = prxposn (rxid, 1, cols[i]);
matches.replace();
end;
end;
if done then matches.output(dataset:'want_matches');
run;
推荐阅读
- php - php imgcropauto 不裁剪图像
- asynchronous - 我不应该在 future::stream::Unfold 上调用 next 吗?
- node.js - 在 MongoDB 中按 INC 值查找文档
- amazon-web-services - RDS 实例和对应的 EC2
- java - 我不知道为什么我的代码给出了错误的答案
- python - 如何将我的训练数据集(通过 TF Dataset API 创建)输入到 RNN/LSTM 模型中?
- html - 相对于 div 的文本布局
- asp.net - 尝试更新 GridView 中的行时出错
- docker - 如何在 docker-compose 中获取服务的别名(备用主机名)?
- reactjs - MobX 类商店与功能性商店