PROC SQL SAS中的长度和浓度
我想为select语句中的某些特定列定义长度,并将两列连接起来,即PROC SQL SAS中的长度和浓度,sas,proc,proc-sql,Sas,Proc,Proc Sql,我想为select语句中的某些特定列定义长度,并将两列连接起来,即赞助商id和赞助商,如SAS proc sql中的“ABC-123”。请帮忙 这是密码 proc sql; select project_id, sponsor_id, empl_country, region, empl_dept_descr, empl_bu_descr, sponsor, full_name, mnth_name FROM Stage
赞助商id
和赞助商
,如SAS proc sql中的“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;
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个字符
剥离意味着删除前导和尾随空格。缺少值的参数不会成为串联的一部分
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个字符
剥离意味着删除前导和尾随空格。缺少值的参数不会成为串联的一部分
如果不知道长度,可以使用strip()函数删除前导空格和尾随空格,在这种情况下,它将删除catx()默认长度生成的空格: 条带(catx('-',赞助商id,赞助商)) 代码:
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;
如果不知道长度,可以使用strip()函数删除前导空格和尾随空格,在这种情况下,它将删除由catx()默认长度生成的空格: 条带(catx('-',赞助商id,赞助商)) 代码:
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;
你试了什么?您知道SAS字符串连接运算符和函数吗?您尝试了什么?您知道SAS字符串连接运算符和函数吗?虽然这段代码只能回答当前的问题,但需要更多的解释来帮助该站点的未来用户了解如何将此解决方案应用于他们的情况。感谢您的注释,我添加了更多关于所用函数的解释。@momo1644-Heyy我发布了一个问题。如果你有空的话,任何机会虽然这段代码的唯一答案可能会解决手头的问题,但需要更多的解释来帮助该网站的未来用户了解如何将此解决方案应用于他们的情况。谢谢你的说明,我已经添加了更多关于所用函数的解释。@momo1644-Heyy我发布了一个问题。如果你有空,有机会吗