BookmarkSubscribeRSS Feed

[SAS 프로그래밍 고수 백승민] [엑셀 Export] 변수명과 라벨 동시에 엑셀로 보내기

Started ‎06-11-2020 by
Modified ‎06-12-2020 by
Views 158

* 엑셀로 데이타 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 */;

Version history
Last update:
‎06-12-2020 01:35 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Article Labels
Article Tags