This post was kindly contributed by SASTechies - go there to comment and to read the full post. |
I believe most of us have encountered this situation…
I have a sas dataset with more than 70k records…How can I provide this information in an Excel file to the business user….
If one is using previous versions of MS Excel ie. < Excel 2007 then one can provide the information in multiple excel sheets in an Workbook…or put it to ,(comma) or a | (pipe) delimited file and then open that with notepad/word application….
if you still wanted to stick with Excel format…then split the dataset to ~65000 rows and load it multiple work sheets in a workbook….
Try with this macro example where I have created a dataset with 1 million records…..This macro then splits the dataset at 65000 records and then dumps the data to multiple worksheets in the Example.xls file….
ExcelXP tagsets are used here that allow us to write to multiple worksheets in a work book….
Inorder to try this example you will have to download this zip file from SAS @ http://support.sas.com/rnd/base/ods/odsmarkup/tagsets_9.1.zip
and then find and extract excltags.tpl file and put it at your C:\ or a location of your choice (In that case please update your location at this statement %include “C:\excltags.tpl”; )
Here’s the code then….
nosource nomprint nomlogic nosymbolgen;
Macro-
No ofobservation to split by)
dataset with 100000 observations*/
splitdsnbyobs(dsn,splitby,ExlFilename,ExlFilepath);
no_obs=&no_obs; /*Get the number of observations in &dsn*/
“C:\excltags.tpl”;
close;
tagsets.excelxp path=“&ExlFilepath”
file=“&ExlFilename” style=printer
embedded_footnotes=‘yes’ suppress_bylines=‘no’);
observations from firstobs= and obs=*/
i=1 %to %sysfunc(ceil(&no_obs/&splitby));
obs=%sysfunc(ceil(%eval(&i
* &splitby.))));
options(sheet_interval=‘none’ sheet_name=“&dsn.&i.”);
run;
tagsets.excelxp close;
splitdsnbyobs;
Dsn with 1000000 observations */
loops;
i=1 to 1000000;
macro to split the observations every 65000 records*/
http://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html
http://support.sas.com/rnd/base/ods/odsmarkup/
http://support.sas.com/rnd/base/ods/odsmarkup/tagsets_9.1.zip
http://support.sas.com/kb/32/394.html
http://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html
This post was kindly contributed by SASTechies - go there to comment and to read the full post. |