SAS 安全列名称(更新) [英] SAS Safe Column Names (Updated)
问题描述
SAS 中是否有一种简单的方法可以将字符串转换为可用作列名的 SAS 安全名称?
Is there a simple way in SAS to convert a string to a SAS-safe name that would be used as a column name?
即.
Rob Penridge ----> Rob_Penridge
$*@'Blah@* ----> ____Blah__
我正在使用 proc 转置
,然后想在转置后使用重命名的列.
I'm using a proc transpose
and then want to work with the renamed columns after the transpose.
8 年的随访……现在有更好的方法来做到这一点吗?我觉得我在某个时候看到了一种更好的方法,但现在我正在努力寻找任何文档/示例,因为我需要这样做.
8 year follow-up... is there now a better way to do this? I feel like I saw a better method sometime back but I'm struggling to find any documentation/examples now that I need to do it.
推荐答案
proc transpose
将采用那些名称而无需任何修改,只要您设置 options validvarname=any;
proc transpose
will take those names without any modification, as long as you set options validvarname=any;
如果您想在之后处理列,您可以使用 NLITERAL 函数来构造可用于引用它们的命名文字:
If you want to work with the columns afterwards, you can use the NLITERAL function to construct named literals that can be used to refer to them:
options validvarname=any;
/* Create dataset and transpose it */
data zz;
var1 = "Rob Penridge";
var2 = 5;
output;
var1 = "$*@'Blah@*";
var2 = 100;
output;
run;
proc transpose
data = zz
out = zz_t;
id var1;
run;
/* Refer to the transposed columns in the dataset using NLITERAL */
data _null_;
set zz;
call symput(cats("name", _n_), nliteral(var1));
run;
data blah;
set zz_t;
&name1. = &name1. + 5;
&name2. = &name2. + 200;
run;
这篇关于SAS 安全列名称(更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!