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;
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.
proc freq and proc means and reports how to sort
@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.
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;
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;
Supply usable example data, so we can show you.
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.