BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

I want to export the command below to excel as 3 different sheet or 3 different excel files. I want it to do this every 900.000 rows. And ı have tried another method and it didnt work. Can you help me about this? Unfortunately i dont have data about the problem. So i can only send the code.

 

PROC EXPORT DATA= HVERGI.Sorgulanacak_vergi_plaka_1 (WHERE=( _N_ < 900001))
            OUTFILE= "D:\SAS\HVERGI\SORGULANACAK_VERGI_PLAKA_1_2.xlsx" 
            DBMS=EXCEL REPLACE;
     SHEET="VP1"; 
RUN;
/*---------------------------------------------------------------------------------------------------------------*/
options obs= 900000;
PROC EXPORT DATA= HVERGI.Sorgulanacak_vergi_plaka_1 DBMS=xlsx OUTFILE= "D:\SAS\HVERGI\SORGULANACAK_VERGI_PLAKA_1_3.xlsx" REPLACE; RUN; options firstobs= 900001; options obs= 1800000; PROC EXPORT DATA= HVERGI.Sorgulanacak_vergi_plaka_1 DBMS=xlsx OUTFILE= "D:\SAS\HVERGI\SORGULANACAK_VERGI_PLAKA_1_4.xlsx" REPLACE; RUN; options firstobs= 1800001; options obs= max; PROC EXPORT DATA= HVERGI.Sorgulanacak_vergi_plaka_1 DBMS=xlsx OUTFILE= "D:\SAS\HVERGI\SORGULANACAK_VERGI_PLAKA_1_5.xlsx" REPLACE; RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the dataset options FIRSTOBS and OBS rather than the system options.

No need to post your data as we can write the program using one of the available datasets in SASHELP library.

 

%let path=%sysfunc(pathname(work));

proc export data=sashelp.class (firstobs=1 obs=6)
   outfile= "&path/one.xlsx"
   dbms=xlsx replace
;
  sheet="one";
run;

proc export data=sashelp.class (firstobs=7 obs=12)
   outfile= "&path/two.xlsx"
   dbms=xlsx replace
;
  sheet="two";
run;

View solution in original post

6 REPLIES 6
ballardw
Super User

I expect that you had a number of error messages. It is often helpful to explain those when shown.

 

When using the Firstobs and obs DATASET options they go in parantheses after the data set:

 

data = mydata (firstobs=900001 obs=1800000);

turcay
Lapis Lazuli | Level 10

Thank you ballardw.

I ran the second code i created and I didnt receive any errors. Though, is there another method? Such as writing as sheets and writing seperate excel files. For example, first 900000 rows will be one sheet and second 900000 rows will be another sheet. 

turcay
Lapis Lazuli | Level 10

In the first code, program see _n_ as like column and gets error. after the where statement what do i have to write instead of _n_. ? As you know _n_ option provides rows of count.

 

Thank you.

turcay
Lapis Lazuli | Level 10

Is it possible to use where statement to reach my aim. As i said i tried the code like as below but it didn't work.

 

PROC EXPORT DATA= HVERGI.Sorgulanacak_vergi_plaka_1 (WHERE=( _N_ < 900001))
            OUTFILE= "D:\SAS\HVERGI\SORGULANACAK_VERGI_PLAKA_1_2.xlsx" 
            DBMS=EXCEL REPLACE;
     SHEET="VP1"; 
RUN;
Tom
Super User Tom
Super User

Use the dataset options FIRSTOBS and OBS rather than the system options.

No need to post your data as we can write the program using one of the available datasets in SASHELP library.

 

%let path=%sysfunc(pathname(work));

proc export data=sashelp.class (firstobs=1 obs=6)
   outfile= "&path/one.xlsx"
   dbms=xlsx replace
;
  sheet="one";
run;

proc export data=sashelp.class (firstobs=7 obs=12)
   outfile= "&path/two.xlsx"
   dbms=xlsx replace
;
  sheet="two";
run;
turcay
Lapis Lazuli | Level 10

Thank you Tom. I will consider your recommendation but it goes without saying that sometimes i need to post my data to better explanation.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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