Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

Solved
Occasional Contributor
Posts: 12

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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....

Accepted Solutions
Solution
‎07-15-2011 09:10 AM
Frequent Contributor
Posts: 82

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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);

All Replies
Frequent Contributor
Posts: 82

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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);

Occasional Contributor
Posts: 12

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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...

Solution
‎07-15-2011 09:10 AM
Frequent Contributor
Posts: 82

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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);

Occasional Contributor
Posts: 12

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

Hey,

It worked fine, Great help ....

Much appreciated...

Posts: 3,852

Could any one let me know whether multiple datasets can be sorted in a sigle sort step?

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;

🔒 This topic is solved and locked.