美文网首页SAS学习笔记
SAS函数:常用的3个拼接函数

SAS函数:常用的3个拼接函数

作者: RSP小白之路 | 来源:发表于2022-11-24 23:26 被阅读0次
  1. cat函数
    函数结构:cat(str1, str2, str3, ...)
    函数作用:将字符数据按罗列顺序前后拼接,不去除空格
    举例:
data dt1;
    length year month day $10;
    input year month day ;
    date = cat(year,'-' ,month,'-' ,day);
cards;
2012 12 23
2014 05 10
2014 07 15
2015 09 12
;
run;

数据集如下:


dt1数据集

注意:
可以看到,length year month day $10;规定了year month day的长度,cat没有去除空格;

  1. cats函数
    函数结构:cats(str1, str2, str3, ...)
    函数作用:将字符数据按罗列顺序前后拼接,去除空格,且如有缺失值仍会进行拼接
    举例:
data dt2;
    length year month day $10;
    infile datalines  delimiter =",";
    input year month day ;
    date = cats(year,'/' ,month,'/' ,day);
datalines;
2012, 12 ,23,
2014, 05 ,,
2014,  ,15,
2015 ,09, 12,
;
run;

数据集如下:

dt2数据集
注意:
可以看到,length year month day $10;虽然规定了year month day的长度,但cats将多余的空格去掉了;而对于缺失的数据,仍然进行了拼接;
  1. catx函数
    函数结构:catx(sep,str1, str2, str3, ...)
    函数作用:sep是规定的分隔符,catx函数将字符数据前后拼接,中间分隔符相连。去除空格,且如有缺失值则不进行拼接
    举例:
data dt3;
    length year month day $10;
    infile datalines  delimiter =",";
    input year month day ;
    date = catx("-",year,month,day);
datalines;
2012, 12 ,23,
2014, 05 ,,
2014,  ,15,
2015 ,09, 12,
;
run;

数据集如下:


dt3数据集

注意:
可以看到,length year month day $10;虽然规定了year month day的长度,但catx将多余的空格去掉了;而对于缺失的数据,则被删除掉没有进行拼接。

相关文章

  • SAS常用函数

    1.数值相关的函数 obs(x):返回绝对值。 exp(x):返回x的指数值。sqrt(x):返回x的平方。 ...

  • sas常用函数

    常用函数

  • python中常用的内建函数

    python中常用的内建函数 总结了python中常用的内建函数。 字符串内建函数 join 拼接字符串 完整的简...

  • go 实现 implode 方法

    impolde 方法是 php 中常用的字符串拼接方法, 在golang 中也有字符串拼接的函数: 此函数与imp...

  • SQL常用字符串与日期处理

    一、常用字符串处理: 1、拼接: a.直接拼接(1)concat()函数直接拼接:concat(str1, str...

  • SAS函数

    ="'"&A2&"'"&","%sysexec md "P:\EC\data_summary&month" & e...

  • 2019-04-19(2)

    MYSQL 常用函数 Concat() 拼接字符串 ltrim() 取除左边空格 rtrim () 取除...

  • php-常用函数

    常用函数 常用函数: 数组常用函数

  • Lesson 3 SAS实用函数

    Lesson 3 SAS实用函数 (1)与数值有关的函数 数值运算 数值舍入 (2)与统计有关的函数 统计描述 函...

  • excel 常用快捷键及函数

    1.常用快捷键 2.常用函数 ①零件函数 日期函数 文本函数 统计函数 随机函数 ②if函数

网友评论

    本文标题:SAS函数:常用的3个拼接函数

    本文链接:https://www.haomeiwen.com/subject/katffdtx.html