BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5


Exporting the data :

As per the req i will create some dataset 10 to 1 crore and i wnat to export it to excel as xlsx is having a limit of
10,50,000(Approx 10 lac 50 thousand) and now i am doing manually and doing first obs and last obs and splitting the dataset to 10 lac and exporting
it how can i do it automatically and it should make the count and export to xls if the count is 65 lacs it should go to 7 excels of 10 lacs each

2 REPLIES 2
esjackso
Quartz | Level 8

Something like this should work if I understand the problem correctly (10 lacs 50 thousand or 1 million 50 thousand rows [the actual limit in excel 2007 to 2010 I believe is 1,048,576 rows]), and this is for separate workbooks instead of worksheets but it could do either with some adjustment:

options mprint mlogic symbolgen;

%macro split(name,path);

Data _null_;

     dsid = open("&name");

  n = attrn(dsid,'nobs');

  call symput('n',n);

run;

%put &n;

%do int = 1 %to &n %by 1000;

libname out excel "&path.\Out_&int..xlsx";

data _null_;

  obs = &int + 1000;

  call symput('obs',obs);

run;

%put &obs;

data out.OUT∫

  set &name (firstobs=&int obs=&obs);

run;

libname out clear;

%end;

%mend split;

%split(temp,/*insert Path here*/);

Haikuo
Onyx | Level 15

For an efficient and true dynamic approach, I prefer Hash plus excel libname engine: The following example is to split class into 5 students per sheet, and end up with 4 sheets.

libname test "c:\temp\test.xlsx";

data _null_;

  declare hash h(ordered:'a');

h.definekey('n');

  h.definedata('name','age','weight');

h.definedone();

do n=1 to 5 until (last);

  set sashelp.class end=last;

  h.add();

end;

h.output(dataset: cats('test.split',_n_));

run;

libname test clear;

Haikuo

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 961 views
  • 0 likes
  • 3 in conversation