Sorting requires a data order. What data order do you want?
Do you want to sort all datasets using the same BY-statement?
how about this code
%Macro MALLSORT(lib=,sortvar=);
data _null_;
set sashelp.vstable;
where libname=upcase("&lib");
call symputx(cats('ds',_N_),memname);
call symputx('nobs',_N_);
run;
%do i=1 %to &nobs;
proc sort data=&&ds&i;
by &sortvar;
run;
%end;
%Mend;
No macro needed, only macro variables:
data _null_;
set sashelp.vtable;
where libname = upcase("&lib.");
call execute("
proc sort data=&lib.." !! strip(memname) !! ";
by &sortvar.;
run;
");
run;
How to call macro from above code
suppose I have datasets in a library like
data ds1;
set sashelp.class;
run;
data ds2;
set sashelp.cars;
run;
data ds3;
set sashelp.air;
run;
And what would be the common variable(s) to sort by?
No common variable for those datasets
class
cars
air
@BrahmanandaRao wrote:
No common variable for those datasets
class
cars
air
Don't use a macro at all, but proc sort directly. Will improve readability of the code as bonus effect.
Then you are obviously in the wrong thread, because you answered @andreas_lds 's question:
Do you want to sort all datasets using the same BY-statement?
with
Yes
so your new question doesn't belong here.
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.