首页 > 解决方案 > 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;

标签: arrayssashashtable

解决方案


正则表达式模式中的分组将设置检索匹配项所需的条件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;

推荐阅读