BookmarkSubscribeRSS Feed
Balaji_7992
Calcite | Level 5

I do have one dataset having 10,000 observations. Here i need to export 500 observations each sheet in same excel file.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Create a variable (which I shall name GROUP) such that the first 500 records have value 1, and the next 500 have value 2, and so on; and then do PROC PRINT with a BY statement and use the ODS EXCEL option sheet_interval='BYGROUP'

 

Example:

 

ods excel file='myexcelfilename.xlsx' options(sheet_interval="BYGROUP");
proc print data=have;
    by group;
run;
ods excel close

or, thinking out of the box, make your life easy, don't split the data up like this, which is much easier to do, and probably much easier on whoever is going to receive this Excel file as well.

--
Paige Miller
Ksharp
Super User

Also could run multiple RPOC EXPORT (write a macro to wrap it)

proc export data=have(obs=500) outfile='c:\temp\want.xlsx' dbms=xlsx replace;
sheet='1-500';
run;

proc export data=have(firstobs=501 obs=1000) outfile='c:\temp\want.xlsx' dbms=xlsx replace;
sheet='501-1000';
run;
...............

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2996 views
  • 3 likes
  • 3 in conversation