BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maggi2410
Obsidian | Level 7

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

That option came out with 9.2

View solution in original post

10 REPLIES 10
art297
Opal | Level 21

Have you tried the label option without the putnames option?

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

maggi2410
Obsidian | Level 7

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

art297
Opal | Level 21

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;

maggi2410
Obsidian | Level 7

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

art297
Opal | Level 21

That option came out with 9.2

Ksharp
Super User

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

data_null__
Jade | Level 19

Ksharp wrote:

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

Check out NLITERAL function.

Ksharp
Super User

Ha. That could make my code better and stronger .

ezetina
Calcite | Level 5

I found this SAS sample useful

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

Ksharp
Super User

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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