Sas 将变量名称更改为其标签
如何将变量名称(Sas 将变量名称更改为其标签,sas,Sas,如何将变量名称(col1、col2、.)更改为这些标签 我使用procglmmod将所有分类变量的虚拟矩阵放入其他数据集中。但是我无法获得变量的原始名称。这里是SAS提供的代码 /* Sample data set with variables containing labels */ data t1; label x='this_x' y='that_y'; do x=1,2; do y=3,4; z=100; output;
col1、col2、.
)更改为这些标签
我使用proc
glmmod
将所有分类变量的虚拟矩阵放入其他数据集中。但是我无法获得变量的原始名称。这里是SAS提供的代码
/* Sample data set with variables containing labels */
data t1;
label x='this_x' y='that_y';
do x=1,2;
do y=3,4;
z=100;
output;
end;
end;
run;
/* Functions such as OPEN, ATTRN, VARNAME, and VARLABEL are used to retrieve variable names and */
/* labels. Macro variables are then created to hold the variable names and variable labels. */
/* We then loop through the number of variables (&num) in the data set passed to the macro (t1). */
/* If a variable contains a label, then the RENAME statement in PROC DATASETS is generated to */
/* contain the proper renaming. */
%macro chge(dsn);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nvars));
%do i= 1 %to #
%let var&i=%sysfunc(varname(&dsid,&i));
%let lab&i=%sysfunc(varlabel(&dsid,&i));
%if &&lab&i = %then %let lab&i=&&var&i;
%end;
%let rc=%sysfunc(close(&dsid));
proc datasets;
modify &dsn;
rename
%do j = 1 %to #
%if &&var&j ne &&lab&j %then %do;
&&var&j=&&lab&j
%end;
%end;;
quit;
run;
%mend chge;
%chge(t1)
proc contents;
run;
这是SAS的代码,可以做到这一点
/* Sample data set with variables containing labels */
data t1;
label x='this_x' y='that_y';
do x=1,2;
do y=3,4;
z=100;
output;
end;
end;
run;
/* Functions such as OPEN, ATTRN, VARNAME, and VARLABEL are used to retrieve variable names and */
/* labels. Macro variables are then created to hold the variable names and variable labels. */
/* We then loop through the number of variables (&num) in the data set passed to the macro (t1). */
/* If a variable contains a label, then the RENAME statement in PROC DATASETS is generated to */
/* contain the proper renaming. */
%macro chge(dsn);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nvars));
%do i= 1 %to #
%let var&i=%sysfunc(varname(&dsid,&i));
%let lab&i=%sysfunc(varlabel(&dsid,&i));
%if &&lab&i = %then %let lab&i=&&var&i;
%end;
%let rc=%sysfunc(close(&dsid));
proc datasets;
modify &dsn;
rename
%do j = 1 %to #
%if &&var&j ne &&lab&j %then %do;
&&var&j=&&lab&j
%end;
%end;;
quit;
run;
%mend chge;
%chge(t1)
proc contents;
run;
这是SAS的代码,可以做到这一点
/* Sample data set with variables containing labels */
data t1;
label x='this_x' y='that_y';
do x=1,2;
do y=3,4;
z=100;
output;
end;
end;
run;
/* Functions such as OPEN, ATTRN, VARNAME, and VARLABEL are used to retrieve variable names and */
/* labels. Macro variables are then created to hold the variable names and variable labels. */
/* We then loop through the number of variables (&num) in the data set passed to the macro (t1). */
/* If a variable contains a label, then the RENAME statement in PROC DATASETS is generated to */
/* contain the proper renaming. */
%macro chge(dsn);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nvars));
%do i= 1 %to #
%let var&i=%sysfunc(varname(&dsid,&i));
%let lab&i=%sysfunc(varlabel(&dsid,&i));
%if &&lab&i = %then %let lab&i=&&var&i;
%end;
%let rc=%sysfunc(close(&dsid));
proc datasets;
modify &dsn;
rename
%do j = 1 %to #
%if &&var&j ne &&lab&j %then %do;
&&var&j=&&lab&j
%end;
%end;;
quit;
run;
%mend chge;
%chge(t1)
proc contents;
run;
这是SAS的代码,可以做到这一点
/* Sample data set with variables containing labels */
data t1;
label x='this_x' y='that_y';
do x=1,2;
do y=3,4;
z=100;
output;
end;
end;
run;
/* Functions such as OPEN, ATTRN, VARNAME, and VARLABEL are used to retrieve variable names and */
/* labels. Macro variables are then created to hold the variable names and variable labels. */
/* We then loop through the number of variables (&num) in the data set passed to the macro (t1). */
/* If a variable contains a label, then the RENAME statement in PROC DATASETS is generated to */
/* contain the proper renaming. */
%macro chge(dsn);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nvars));
%do i= 1 %to #
%let var&i=%sysfunc(varname(&dsid,&i));
%let lab&i=%sysfunc(varlabel(&dsid,&i));
%if &&lab&i = %then %let lab&i=&&var&i;
%end;
%let rc=%sysfunc(close(&dsid));
proc datasets;
modify &dsn;
rename
%do j = 1 %to #
%if &&var&j ne &&lab&j %then %do;
&&var&j=&&lab&j
%end;
%end;;
quit;
run;
%mend chge;
%chge(t1)
proc contents;
run;
我有60个变量,所以一个一个的去做太难了。一个人可以看到这个问题,因为这个问题的反义词是GLMMOD返回的是标签,而不是varname?如果是这样,为什么不在使用GLMMOD之前删除标签(如链接问题中所示)?或者GLMMOD正在创建具有通用名称和原始名称作为标签的变量?示例代码和所需的输入/输出会很有用。我有60个变量,所以很难一个一个地做。一个人可以看到这个问题,因为这个问题的反义词GLMMOD是返回标签,而不是varname?如果是这样,为什么不在使用GLMMOD之前删除标签(如链接问题中所示)?或者GLMMOD正在创建具有通用名称和原始名称作为标签的变量?示例代码和所需的输入/输出会很有用。我有60个变量,所以很难一个一个地做。一个人可以看到这个问题,因为这个问题的反义词GLMMOD是返回标签,而不是varname?如果是这样,为什么不在使用GLMMOD之前删除标签(如链接问题中所示)?或者GLMMOD正在创建具有通用名称和原始名称作为标签的变量?示例代码和所需的输入/输出会很有用。我有60个变量,所以很难一个一个地做。一个人可以看到这个问题,因为这个问题的反义词GLMMOD是返回标签,而不是varname?如果是这样,为什么不在使用GLMMOD之前删除标签(如链接问题中所示)?或者GLMMOD正在创建具有通用名称和原始名称作为标签的变量?示例代码和所需的输入/输出将非常有用。太好了,谢谢你的帮助太好了,谢谢你的帮助太好了,谢谢你的帮助太好了,谢谢你的帮助