在 var 名称中有空格的 sas7bdat [英] sas7bdat with spaces in var names

查看:32
本文介绍了在 var 名称中有空格的 sas7bdat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了几个扩展名为 .sas7bdat 的 SAS 数据集文件.我在 Windows 上使用 SAS 9.3,这些文件的创建者显然使用了不同的环境和/或软件.许多文件的 var 名称包含空格和其他无效字符.即使运行 proc contents 也会引发这样的错误:

I've received several SAS dataset files with the .sas7bdat extension. I'm using SAS 9.3 on windows, and the creator of these files was evidently using a different environment and/or software. Many of the files have var names that include spaces and other invalid characters. Even running a proc contents raises an error like this:

ERROR: The value Person ID is not a valid SAS name.

奇怪的是,SAS Enterprise Guide 打开并显示文件没有任何抱怨.

Oddly, SAS Enterprise Guide opens and displays the file without complaining.

如何有效地重命名所有错误的 var 名称,以便我可以开始使用这些文件运行实际程序?

How do I efficiently re-name all my bad var names so that I can start running actual programs with these files?

推荐答案

除了 option validvarname=ANY; 你还需要引用变量名作为名称文字:'Person ID'n(单引号或双引号都可以).

In addition to option validvarname=ANY; you also need to reference the variable names as name literals: 'Person ID'n (either single or double quotes are fine).

如果你想有效地重命名所有这些,你可以这样做:

If you want to efficiently rename all of them, you can do something like this:

options validvarname=any;
data have;
'Hello Var'n = 1;
'Another Var'n = 2;
x=3;
run;

data badvarnames;
set sashelp.vcolumn;
where libname='WORK' and memname='HAVE' and not nvalid(name,'v7');
validname = translate(trim(name),'_',' ');
name = cats("'",name,"'n");
run;

proc sql;
select catx(' ','rename',name,'=',validname,';') into :renamelist
separated by ' ' from badvarnames;
quit;

proc datasets lib=work;
modify have;
&renamelist;
quit;

proc contents data=have;
run;

根据其他细节(例如这可能会导致变量名称重叠),您可能需要针对这些问题调整代码.

Depending on other details (such as the possibility that this might create overlapping variable names), you might need to adjust the code for those concerns.

这篇关于在 var 名称中有空格的 sas7bdat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆