This code is used to sort variable names in a dataset. Means placing variables in ascending order in a dataset according to their names.
For more information, see the comments in code.
Here just you need to provide the library name and dataset name in which you want to see the variable names in their ascending order.
SAS Code:
/* options to print resolved macro code in log file */
options mlogic mprint symbolgen;
/* Macro code to sort variable names in a dataset */
%macro var_sort(library=,dataset=);
proc sql noprint;
select strip(name) into :vars separated by ' '
from dictionary.columns
where libname=upcase("&library") and memname=upcase("&dataset")
order by 1;
quit;
data &library..&dataset;
retain &vars;
set &library..&dataset;
run;
%mend var_sort;
/* end of the macro code */
/* Here just you need to provide the library name and dataset name in which you want to see the variable
names in their ascending order */
%var_sort(library=work,dataset=sample);
/*###########################################################################*/
/* Sample data to test this macro code */
data work.sample;
xy=1;
zx=2;
dc=3;
ab=4;
aa=1;
a=2;
cd='A';
run;
/* end of the sample data */
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment