I have a dataset with labels that I want to export to excel, but the label statement won't turn blue or export the label. 'About SAS 9' indicates I have SAS 9.4 TS Level 1M5, so the label statement should work... putnames doesn't work either. I tried to rename the variable itself, but they contain special characters (e.g. #). How can I export the dataset to excel with labels?
proc export data=missingReport outfile="C:location\filename.xlsx" dbms=xlsx label replace; sheet="missingFacilities"; run;
Works fine for me:
data class;
set sashelp.class;
label name='Student Name';
run;
proc export label data=class dbms=xlsx
file='c:\downloads\labels.xlsx' replace;
run;
Make sure to attach the labels BEFORE the PROC EXPORT step.
You don't have to make a copy of the dataset, you can use PROC DATASETS to modify the labels without copying the dataset.
If the variable names do not meet SAS naming rules then you will need to use name literals in the LABEL statement.
label 'job#'n ='Job Number';
Works fine for me:
data class;
set sashelp.class;
label name='Student Name';
run;
proc export label data=class dbms=xlsx
file='c:\downloads\labels.xlsx' replace;
run;
Make sure to attach the labels BEFORE the PROC EXPORT step.
You don't have to make a copy of the dataset, you can use PROC DATASETS to modify the labels without copying the dataset.
If the variable names do not meet SAS naming rules then you will need to use name literals in the LABEL statement.
label 'job#'n ='Job Number';
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.