- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-07-2022 04:41 AM
(1471 views)
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 |
… | … | … | … | … | … | … |
… | … | … | … | … | … | … |
… | … | … | … | … | … | … |
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do your column names follow typical naming conventions (begin with a letter or underscore, use up to 32 letters, numbers and underscores)? If so, this is a straightforward problem. If not, we have some hoops to jump through.
Also note what it means to use alphabetical order. If you have names 2, 3, 5, 15, 20, alphabetical order would mean 15, 2, 20, 3, 5. Is that what you want?
Also note what it means to use alphabetical order. If you have names 2, 3, 5, 15, 20, alphabetical order would mean 15, 2, 20, 3, 5. Is that what you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;