我使用以下方法从数据集中删除标签:
proc datasets lib=my_lib memtype=data nolist ;
modify my_data_1 ;
attrib _all_ label=' ';
run;
quit;
我想为几个数据集my_data_1,...,my_data_n执行此操作。使用以下命令返回错误(期待;,/):
proc datasets lib=my_lib memtype=data nolist ;
modify my_data_1 my_data_2 my_data_3 ; * and so on ... *;
attrib _all_ label=' ';
run;
quit;
我想知道是否有办法将例外应用于以下内容:
proc datasets lib=my_lib memtype=data nolist ;
modify _all_ ;
attrib _all_ label=' ';
run;
quit;
我想要修改的数据集占大多数,这样会更有效。
答案 0 :(得分:2)
更简单的方法是使用复制和选择,例如:
proc datasets ;
copy in=sashelp out=work;
select cars baseball;
attrib _all_ label=' ';
run;
答案 1 :(得分:1)
构建数据集为数据集及其上的变量分配标签;
options mprint;
%macro createThem;
%do i = 1 %to 3;
data my_data_&i. (label="Set &i.");
label j="Set &i.";
do j = 1 to &i;
output;
end;
run;
%end;
%mend;
%createThem;
证明此成功;
proc sql;
select memname, memlabel from sashelp.vtable
where libname='WORK' and memname like 'MY_DATA%';
select memname, name, label from sashelp.vcolumn
where libname='WORK' and memname like 'MY_DATA%';
run;
编写宏以从一个数据集中删除标签;
%macro eraseLabel(data);
proc datasets lib=WORK memtype=data nolist ;
modify &data. (label=' '); ** Remove label form dataset **;
attrib _all_ label=' '; ** Remove label form variable(s) **;
run;
quit;
%mend;
将此宏应用于所涉及的数据集;
data _null_;
set sashelp.vtable;
where libname='WORK' and memname like 'MY_DATA%';
call execute('%eraseLabel('||memname||')');
run;
证明此成功;
proc sql;
select memname, memlabel from sashelp.vtable
where libname='WORK' and memname like 'MY_DATA%';
select memname, name, label from sashelp.vcolumn
where libname='WORK' and memname like 'MY_DATA%';
run;
答案 2 :(得分:1)
这里的另一种方法是构建对proc datasets
的单个调用,它将使用proc中的多个run;
组一次性完成所有操作。目标是构建这样的东西:
data example1 example2;
set sashelp.class;
label sex = 'example label';
run;
proc datasets lib = work nolist;
modify example1;
attrib _all_ label = '';
run;
modify example2;
attrib _all_ label = '';
run;
quit;
这可以通过相当简单的宏循环或带有调用execute的数据步骤来实现,例如
data _null_;
set sashelp.vtable end = eof;
where libname = 'WORK' and memtype = 'DATA' and memname eq: 'EXAMPLE';
if _n_ = 1 then call execute('proc datasets lib = work nolist nodetails;');
call execute(catx(' ','modify',memname,'; attrib _all_ label = ""; run;'));
if eof then call execute('quit;');
run;