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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 939 views
  • 0 likes
  • 3 in conversation