* 엑셀로 데이타 Export시에 사용자에게 변수명과 라벨을 같이 보여주고 싶을때 사용하면 편리한 프로그램 이네요;
* 출처 : http://support.sas.com/kb/35/574.html;
* Varlabelmaker91 *;
* purpose: to export variable names and labels to the same top cell in an excel *;
* worksheet *;
* Parameters required , name of the sas dataset, excel workbook, worksheet, and *;
* a location to write the temporary labeler routine *;
**********************************************************************************;
options mprint macrogen symbolgen;
%macro labelvar(sasdata,xlsname,sheetnam,sasprog);
options source2;
ods trace on;
ods output variables=varvol1;
proc contents data=&sasdata;
run;
ods trace off;
run;
data varvol2; set varvol1;
mergednewvar='"'||left(trim(variable))||'-'||left(trim(label))||'"';
run;
data _null_; set varvol2;
file "&sasprog";
put 'label ' variable ' = ' mergednewvar ';' ;
run; quit;
data temp1; set &sasdata;
%include "&sasprog";
run;
libname myexcel excel &xlsname;
proc sql;
drop table myexcel.&sheetnam;
quit;
data myexcel.&sheetnam (dblabel=yes); set temp1;
run;
quit;
libname myexcel clear;
%mend;
%labelvar(sasuser.baseball, /* name of sas dataset */
'c:\sastest\book1.xls', /* name of the excel file, keep the quotes*/
newsheet, /* name of the worksheet */
c:\sastest\mylabeler.sas); /* name of the place to write the sas label routine */;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.