PROC SQL SAS中的长度和连续

问题描述 投票:0回答:2

我想在select语句中为某些特定列定义长度,我想在SAS proc sql中连接两列,即sponsor idsponsor,如“ABC-123”。请帮忙这里是代码

proc sql;
select
    project_id,
    sponsor_id,

    empl_country,
    region,
    empl_dept_descr,
    empl_bu_descr,

    sponsor,
    full_name,
    mnth_name FROM Stage0;
quit;
sas proc proc-sql
2个回答
1
投票

如果您不知道长度,可以使用strip()函数来删除前导和尾随空格,在这种情况下,它将删除catx()默认长度生成的空格:

strip(catx(' - ',sponsor_id,sponsor))

码:

proc sql;
select
    project_id,
    sponsor_id,

    empl_country,
    region,
    empl_dept_descr,
    empl_bu_descr,

    sponsor,
    full_name,
    mnth_name ,

/* New column */
strip(catx('-', sponsor_id, sponsor)) as new_id

FROM Stage0;
quit;

3
投票

CATX函数将连接任意数量的任何类型的参数,剥离值并在每个参数之间放置一个公共分隔符(也被剥离)。例如:

proc sql;
  create table want as
  select 
    catx('-', name, age) as name_age length=20
  , catx(':', name, sex, height) as name_gender_height
  from sashelp.class;

如果分配CATX结果的变量没有指定长度,则新变量的长度将为200个字符。

剥离意味着删除前导和尾随空格。缺少值的参数不会成为串联的一部分。

SAS Documentation for CATX

© www.soinside.com 2019 - 2024. All rights reserved.