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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.