【问题标题】:find string containing alphanumeric value in sas在 sas 中查找包含字母数字值的字符串
【发布时间】:2017-06-13 08:05:58
【问题描述】:

我想查找包含字母数字值的变量,例如 123asd 或数值 123 到 9 的 1 到 9 的任意组合。如果存在,则使用“找到”文本创建新列。

代码:

 data one;
 input Val $;

 datalines;
 abc.400
 300.bef
 3456321
 abcdefg
 123.234
 ;

 proc print;
 run;

输出应该是

  value    tag
 abc.400  found
 300.bef  found
 3456321  found
 abcdefg  nofound
 123.234  found

【问题讨论】:

    标签: database sas dataset


    【解决方案1】:

    任意位函数。

    flag=ifc(anydigit(Val)>0,'Found','NoFound');
    

    【讨论】:

    • 它给了我一个错误,称为函数 ifc is unknown or cannot be access 。
    • 如果它们的大小小于 7 个字符,也希望显示未找到示例:Val tag 21312 Not found
    【解决方案2】:

    您可以使用compress()kd(保留数字)第三个参数,然后使用missing() 来查看是否返回任何内容。我把它放在一个带有ifc 的单行中,这是一种 excel 风格的 if(如果为 true,则返回第二个参数,如果为 false,则返回第三个参数,返回字符)。

    tag = ifc(missing(compress(value,,'kd')),'nofound','found')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 2021-07-19
      • 2011-05-23
      • 1970-01-01
      • 2014-10-01
      相关资源
      最近更新 更多