BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I want to export first 5 observations.

What is the way to do directly in proc export please?

 

Then I want also to export observations 6-10

What is the way to do directly in proc export please?

 PROC EXPORT data =sashelp.cars(Where=(_N_<=5)) outfile ="path/dd.csv";
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the OBS= and FIRSTOBS= dataset option.

sashelp.cars(obs=5)

sashelp.cars(firstobs=6 obs=10)

sashelp.cars(firstobs=11 obs=15)

...

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
proc export data=sashelp.cars(obs=5) outfile ="path/dd.csv";
run;

 

_N_ only has meaning within a data step, it has no meaning elsewhere.

--
Paige Miller
Astounding
PROC Star

To export observations 6 through 10:

proc export data=sashelp.cars (firstobs=6 obs=10) outfile ="folder/next5.csv";
run;
Tom
Super User Tom
Super User

Use the OBS= and FIRSTOBS= dataset option.

sashelp.cars(obs=5)

sashelp.cars(firstobs=6 obs=10)

sashelp.cars(firstobs=11 obs=15)

...

webart999ARM
Quartz | Level 8

To export the first 5 observations using PROC EXPORT, you can use the following code:

 

PROC EXPORT data = sashelp.cars(where=(_N_<=5)) outfile="path/dd.csv";
run;

 

To export observations 6-10 using PROC EXPORT, you can use the following code:

PROC EXPORT data = sashelp.cars(where=(_N_>5) and (_N_<=10)) outfile="path/dd.csv";
run;

 

In both cases, you need to specify the name of the SAS dataset you want to export (in this case, sashelp.cars), the file path and name for the output CSV file (in this case, path/dd.csv), and the WHERE clause that specifies which observations you want to export.

 

Ronein
Meteorite | Level 14
Sorry but your code give an error.
As it was said here we cannot use _N_ in proc export

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1387 views
  • 3 likes
  • 5 in conversation