02-18-2015 01:34 PM
can anyone tell me what would be the code for exporting data to excel and format at the same time?
My table look like this in SAS (year is yy, last_name is not in order, variable name is not bold):
I want my excel table to bring the year as yyyy, last name ascending, variable name bold. It should look like this:
can anyone tell me what would be the code for this? I am using sas 9.4 and office 2010
02-18-2015 01:46 PM
Proc Export will not do what you want. Tagsets.excelxp will create XML that Excel can read and with procedures such as Proc Print, Report and Tabulate provide some of what you want.
The digits in the date variable are likely controlled by the Format associated which looks like it is currently DATE9. Use Date11. for output. The ORDER of appearance would likely want a SORT step.
Proc sort data=have; by Lastname; run;
ods tagsets.excelxp file="C:\folder\myfile.xml" ;
proc print data=have noobs;
var enroll_date first_name last_name birthdate; /* or the order you want the variables to appear*/
format enroll_date birthdate date11.;
ods tagsets.excelxp close;
open the result with excel. The active style will control some font information but column headings in most will be bold.
02-18-2015 04:36 PM
If you have SAS 9.4 you can also try ODS EXCEL but it's still experimental and doesn't work in all circumstances. Just switch the ODS TAGSETS.EXCELXP with ODS EXCEL.
It looks like you might want to customize the width of the columns, you can look into the TAGSETS options to see which ones to set to customize your column widths.
Instead of PROC PRINT consider PROC REPORT which will allow you to create bold headers and/or customized column widths.