- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the OBS= and FIRSTOBS= dataset option.
sashelp.cars(obs=5)
sashelp.cars(firstobs=6 obs=10)
sashelp.cars(firstobs=11 obs=15)
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To export observations 6 through 10:
proc export data=sashelp.cars (firstobs=6 obs=10) outfile ="folder/next5.csv";
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the OBS= and FIRSTOBS= dataset option.
sashelp.cars(obs=5)
sashelp.cars(firstobs=6 obs=10)
sashelp.cars(firstobs=11 obs=15)
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As it was said here we cannot use _N_ in proc export