DATA Step, Macro, Functions and more

labels while proc exporting

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

labels while proc exporting

Hi,

I have a sas dataset with columns having labels. While using the proc export, I want the labels to be the first row in the excel. I have tried label option and putnames=no too. But nothing works for me. Any idea?

Mine is 64 bit SAS and DBMS = excel(not xls) is used.

Thanks!!


Accepted Solutions
Solution
‎08-09-2012 08:29 PM
PROC Star
Posts: 7,360

Re: labels while proc exporting

That option came out with 9.2

View solution in original post


All Replies
PROC Star
Posts: 7,360

Re: labels while proc exporting

Have you tried the label option without the putnames option?

Take a look at: http://support.sas.com/kb/41/735.html

Contributor
Posts: 43

Re: labels while proc exporting

yes..nothing worked for me.. but i got this solution finally:

via libname statement use dslabel dataset option. But it doesnt replace your excel. So you have to add an extra piece of code to do so.

Thanks

PROC Star
Posts: 7,360

Re: labels while proc exporting

The following worked for me:

  /*Modify SASHELP.CLASS to include labels for variables*/

   data newclass;

     set sashelp.class;

     label name='First Name'

           sex='Gender'

           Age='Age of Person'

           Height='Height of Person'

           Weight='Weight of Person';

   run;

   proc export data=newclass outfile='c:\classlabel.xls'

               label dbms=excel replace;

   run;

Contributor
Posts: 43

Re: labels while proc exporting

Great. I guess it depends a lot in your sas version and your platform. Mine is 9.1 on UNIX. and somehow didnt work.

Solution
‎08-09-2012 08:29 PM
PROC Star
Posts: 7,360

Re: labels while proc exporting

That option came out with 9.2

Super User
Posts: 9,671

Re: labels while proc exporting

Just for a fun. You can rename its name to its label before export excel file.

data newclass;
     set sashelp.class;
     label name='First Name'
           sex='Gender'
           Age='Age of Person'
           Height='Height of Person'
           Weight='Weight of Person';
   run;
options validvarname=any;
data _null_;
 set sashelp.vcolumn(keep=libname memname name label where=(libname='WORK' and memname='NEWCLASS')) end=last;
 if _n_ eq 1 then call execute('proc datasets library=work nolist;modify newclass;rename ');
 call execute(cats(name,"='",label,"'n" ));
 if last then call execute(';quit;');
run;



   proc export data=newclass outfile='c:\classlabel.xls'
                dbms=excel replace;
   run;

Ksharp

Respected Advisor
Posts: 3,777

Re: labels while proc exporting

Ksharp wrote:

call execute(cats(name,"='",label,"'n" )); if last then call execute(';quit;'); run;    proc export data=newclass

Check out NLITERAL function.

Super User
Posts: 9,671

Re: labels while proc exporting

Ha. That could make my code better and stronger .

New Contributor
Posts: 4

Re: labels while proc exporting

I found this SAS sample useful

http://support.sas.com/kb/35/574.html

Super User
Posts: 9,671

Re: labels while proc exporting

Of course. If you can accept the non-legitimacy EXCEL file , using PROC REPORT which default use LABEL as header of column.

data newclass;
     set sashelp.class;
     label name='First Name'
           sex='Gender'
           Age='Age of Person'
           Height='Height of Person'
           Weight='Weight of Person';
   run;
ods listing close;
ods tagsets.excelxp file='c:\x.xls' ;
proc report data=newclass  nowd;
run;
ods tagsets.excelxp close;
ods listing;

Ksharp

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 23746 views
  • 2 likes
  • 5 in conversation