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