In reply to Rahul Gupta.

If you submit a PROC with a BY statement, the "order by" directive will push to the database automatically. To keep the sorting in SAS (which you might want to do if you want a specific collating sequence), you would need to pull the working set into SAS first (with a PROC SQL, for example), and then sort the data set with PROC SORT and whatever options you need. Also, remember that some grouping operations do not require sorted data, such as PROC SUMMARY/MEANS with the CLASS statement. In general, if the PROC offers a CLASS statement you can group your calculations across one or more categories without first sorting the data.