I have multiple sas small datasets and need to export the same sheet in Excel workbook. I defined different range cells for each data set in the same sheet. Anyone know how to do this ?
Thanks in advance
One way (but you have no control over the exact positioning of the tables)
ods excel file="myexcelfile.xlsx" options(sheet_interval='NONE');
proc print data=dataset1;
run;
proc print data=dataset2;
run;
ods excel close;
Not sure that this is the "best" approach by any means but I've had to setup a powershell script to re-organize the data before (mainly copy-pasting into macro-enabled workbook). If all else fails you can look into this approach.
How exactly are you going dump multiple datasets into the same worksheet? If the columns are not the same it will look terrible. If they are the same then why not just combine them into one dataset and dump that?
@QLi wrote:
I am using EG7.1, which should with SAS9.4. I wrote the following codes. it can not export the same sheet, each data set automatically generated different sheet.
options noxwait xsync;
x copy "temp_v0.xlsx" &excel_out;
libname xls excel &excel_out ; run;
proc datasets lib = xls nolist;
delete
Summary Rejected1 Rejected2 Point_O_New Point_overall_Existed ;
quit;
data xls.Summary; set RDP_Sum_t ; run;
data xls.Rejected1; set RDP_Sum_Reject ;run;
data xls.Rejected2; set RDP_Sum_Reject2 ; run;
data xls.Point_overall_Existed ; set Point_1(where=( EXISTINGCUSTOMER='true')); run;
libname xls clear;
I will try your approach. Thank you very much
That is not actually "exporting" it is "writing", at least in my mind. Excel is a poor data interchange medium and since data steps write data then SAS has, rightly in my mind, forced writing data sets to spread sheets as separate pages so that you cannot in any way, shape, or form have inconsistent data in a single column.
Nothing like reading the first 600 rows of data as "dates" and then discover at row 602 the data is now "names", phone numbers or similar.
And if the variables are all of the same type and name then combine the SAS data sets and use a single process to write the data.
You could even add a variable as those sets are combined to have information about the data source on each and every record. Your attempted approach does not do that. So even if you succeeded how do you know where the Reject data starts?
I remember there is an option :
ods excel file="myexcelfile.xlsx" options(sheet_interval='NONE' start_at='2,5');
You could search it at blogs.sas.com
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.