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

Hi,

 

If I have a data with var1 and var2, and I wanted the final .csv file to be sorted by var2, my question is:

 

Is it possible to sort the data in a PROC EXPORT step or the data can only be sorted by a PROC SORT before the PROC EXPORT?

 

If it is possible to sort using PROC EXPORT, what's the syntax?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

There is no sort option in PROC EXPORT. You would need to do the sorting in PROC SORT.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

There is no sort option in PROC EXPORT. You would need to do the sorting in PROC SORT.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hi @cosmid,

 

You could define a PROC SQL view including an ORDER BY clause and apply PROC EXPORT to this view. Then the sorting will occur during the PROC EXPORT step and without creating a sorted dataset.

 

Example:

 

data have;
set sashelp.class(keep=age weight);
run;

proc sql;
create view have_s as
select * from have
order by weight;
quit;

proc export data=have_s 
outfile='C:\Temp\want.csv' dbms=csv replace;
run;

 

 

 

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 918 views
  • 1 like
  • 3 in conversation