简体   繁体   English

如何重命名通用sas变量?

[英]How to rename generic sas variables?

I imported a dataset with getnames=no 我导入了一个getnames=no的数据集

proc import out=dstest
datafile

...

run;

and got a bunch of F1-F5 variables 并获得了一堆F1-F5变量

Now I want to rename them 现在我想重命名它们


 data dstest (rename=(F2=newName));
    set dstest ;
    run;

Here is the error 这是错误

The variable F2 in the DROP, KEEP, or RENAME list has never been referenced


data dstest ;
        set dstest(rename=(F2=newName)) ;
        run;

Here is the error 这是错误

 Variable F2 is not on file WORK.dstest.

However proc print works fine 但proc proc工作正常

proc print data=tortdata (obs=10) ;  
var F2;
run;

There's nothing inherently wrong with what you've posted, insomuch as the code should run: 你发布的内容没有任何内在错误,因为代码应该运行:

data blah;
f1=1;
f2=4;
run;

data blah(rename=(f1=a f2=b));
set blah;
run;

However, if you're just renaming the variable, no reason to do a data step. 但是,如果您只是重命名变量,则没有理由进行数据步骤。 PROC DATASETS can handle this without going through the entire dataset. PROC DATASETS无需遍历整个数据集即可处理此问题。 This may not matter much if the dataset is small, but if it is large, this may save a lot of time. 如果数据集很小,这可能无关紧要,但如果数据集很大,这可能会节省大量时间。 Note that you can't run the above and then this, as f1 and f2 will be gone if you don't re-construct the blah dataset. 请注意,如果不重新构造blah数据集,则无法运行上面的内容,因为f1和f2将会消失。

proc datasets lib=work;
modify blah;
rename f1=a f2=b;
quit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM