【问题标题】:Remove last word from string in SAS?从SAS中的字符串中删除最后一个单词?
【发布时间】:2016-01-21 21:22:29
【问题描述】:

我有一个数据集中的县列表(卡尔霍恩县、埃尔帕索县等),我想返回一个删除了“县”一词的数据集(卡尔霍恩、埃尔帕索等)。在SAS中做到这一点的简单方法?谢谢!

【问题讨论】:

    标签: sas


    【解决方案1】:

    CALL SCAN 将报告第 n 个单词的位置,然后您可以将其与 substr 一起使用。 Count=-1 会从结尾而不是开头看。

    data _null_;
      starting_word='El Paso County';
      count=-1;
      call scan(starting_word, count, pos, length);
      end_word=substr(starting_word,1,pos-2); *pos will be the 'C' so back two;
      put end_word=;
    run;
    

    【讨论】:

    • @scott 非常正确。这可以通过在删除之前检查单词是什么来轻松处理。 IE。只有当它是“县”这个词或任何其他不需要的词时才删除它。
    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 2023-02-03
    • 2018-03-27
    • 1970-01-01
    • 2017-07-17
    相关资源
    最近更新 更多