BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Good Morning

Any alternative methods are there sorting the data along with below methods

1.Proc sort

2.Hast Object

3.Proc Sql  ; Order by Clause

data sort;
set sashelp.class;
run;


data _null_;
set sort;
sort_data=cats(('Proc sort data=sort;by sex; run;'));
call execute(sort_data);
run;
10 REPLIES 10
Kurt_Bremser
Super User

Statistical procedures like FREQ or MEANS will sort their outputs, REPORT will sort the result along the variables defined as GROUP.

There's lots of places in SAS where sorting takes place, but for sorting whole datasets, you've listed the tools to use.

BrahmanandaRao
Lapis Lazuli | Level 10

proc freq  and proc means and reports how to  sort 

 

Kurt_Bremser
Super User

@BrahmanandaRao wrote:

proc freq  and proc means and reports how to  sort 

 


As I said, they automatically sort the results, not datasets. Just play around with them.


 

PeterClemmensen
Tourmaline | Level 20

You could use an index

 

proc copy in=sashelp out=work memtype=data;
   select class;
run;
 
proc datasets library=work nolist;
   modify class;
      index delete _all_;
      index create name;
run;quit;
 
data SortIndex;
   set class;
   by name;
run;
Ksharp
Super User

If you have big table, try this one .

 

data F M;
set sashelp.class;
select(sex);
when('F') output F;
when('M') output M;
otherwise;
end;
run;

data sort;
 set F M;
run;
BrahmanandaRao
Lapis Lazuli | Level 10
Hi Sharp
Than you for your smart solution
Suppose we have have sort thru diferrent N no of customer ID s then how can we do this method
Kurt_Bremser
Super User

But note that @Ksharp's method is only feasible for variables with low cardinality. If you try that with a million distinct customers, you will run out of file handles for the datasets.

PaigeMiller
Diamond | Level 26

Here we have a situation that is quite common in the forums, where the focus is so tightly on the mechanics of performing a task (in this case sorting), that we don't understand the bigger problem. This is the XY problem and leads to inefficient dialog and sub-optimal solutions.

 

The larger problem that has led to this emphasis on sorting is never explained, and so we are just shooting in the dark to propose solutions. Perhaps @BrahmanandaRao could explain the problem which leads to this interest in sorting methods, and perhaps then the best solution will be obvious, and we won't waste our time proposing or discussing solutions that aren't helpful in this case.

--
Paige Miller
Ksharp
Super User
Yes. As Kurt pointed out. Show us some sample data .

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 10 replies
  • 1941 views
  • 2 likes
  • 5 in conversation