SAS Programming

DATA Step, Macro, Functions and more
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

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 5 replies
  • 2440 views
  • 3 likes
  • 5 in conversation