Hello,
my dataset has ~100 columns. I want to order the columns alphabetically with sql or sas-code (the Column with the number 1 shall appears first, 2 second and so on)... Is it implementable with little code?
Thank you!
Data have:
| 5 | 3 | 2 | 50 | 6 | 8 | 7 |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
data want:
| 2 | 3 | 5 | 6 | 7 | 8 | 50 |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
| … | … | … | … | … | … | … |
data have;
input var12 var2 var3 var1 var4;
cards;
1 2 3 4 5
;
proc sql noprint;
select name into :names separated by ','
from dictionary.columns
where upcase(libname)='WORK' and upcase(memname)='HAVE'
order by input(compress(name,,'kd'),best.);
create table want as
select &names. from have;
quit;
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.