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;
Use the OBS= and FIRSTOBS= dataset option.
sashelp.cars(obs=5)
sashelp.cars(firstobs=6 obs=10)
sashelp.cars(firstobs=11 obs=15)
...
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.
To export observations 6 through 10:
proc export data=sashelp.cars (firstobs=6 obs=10) outfile ="folder/next5.csv";
run;
Use the OBS= and FIRSTOBS= dataset option.
sashelp.cars(obs=5)
sashelp.cars(firstobs=6 obs=10)
sashelp.cars(firstobs=11 obs=15)
...
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: