**********************************************************************************; * 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 */;