Could any one let me know whether multiple datasets can be sorted in a sigle sort step?
For ex I want to sort datasets A, B and C by variables AA, BB and CC respectively...
Any help is much appreciated....
I think the easiet way would be just writing it together with variables like:
%sort_it(B, var1 descending var2);
%sort_id (AB, descending var1);
Not a single step, but a simple macro could make your code look nice
%macro
sort_it (name, variables);
proc sort data=&name;
by &variables;
run;
%mend;
%sort_it(A, var1);
%sort_it(B, var1 var2);
%sort_id (AB, var1);
Hey ieva,
Thank you for code, one simple concern is order i.e. Ascending and Descending...
If I want to add descending order how we should modify the code above...
Thank you for reply
I think the easiet way would be just writing it together with variables like:
%sort_it(B, var1 descending var2);
%sort_id (AB, descending var1);
Hey,
It worked fine, Great help ....
Much appreciated...
You asked for it, sort 3 data set in one data step by different variables. Silly? I'll let you decide.
data a(keep=aa) b(keep=bb) c(keep=cc);
do _n_ = 10 to 1 by -1;
aa = _n_;
bb = _n_;
cc = _n_;
do j = 1 to 3;
output;
end;
end;
run;
data _null_;
if 0 then set a;
declare hash a(dataset:'A',multidata: 'Y',ordered:'Y');
a.definekey('AA');
a.definedata(all:'Y');
a.defineDone();
a.output(dataset:'SA');
a.clear();
if 0 then set b;
declare hash b(dataset:'B',multidata: 'Y',ordered:'Y');
b.definekey('BB');
b.definedata(all:'Y');
b.defineDone();
b.output(dataset:'SB');
if 0 then set c;
declare hash c(dataset:'C',multidata: 'Y',ordered:'Y');
c.definekey('CC');
c.definedata(all:'Y');
c.defineDone();
c.output(dataset:'SC');
stop;
run;
proc print data=SA;
run;
proc print data=SB;
run;
proc print data=SC;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.