How to sort the COLUMN headers which includes numeric,special characters and also space? I got some idea on column sorting but it applies only for proper SAS COLUMN NAMES which satisfies the rules. The above NUMERIC COLUMNS resulted after using PROC TRANSPOSE.
SAS seems to only put columns in the order that they are created, not numeric or alphabetical order. If you want to specify the order of the columns, I have used one of two ways:
1. Use PROC SQL and use the SELECT statement to list out the columns that you want in the order that you want.
2. Use a DATA step and use the LENGTH statement to specify lengths of the columns in the order that you want (more work and less efficient).
This, however, does not seem too enjoyable if you have a lot of columns. In that case, you could probably try something like:
proc sort data=sashelp.vcolumn (where=(libname='AAA' & memname='BBB')) out=sorted;
by name;
run;
proc sql;
select name into :columns separated by ', '
from sorted
where name not in ('',''); /* fill in the blank single quotes with the names of variables that you are not interested in sorting */
create table sortedColumns as
select &columns.
from AAA.BBB;
quit;
In the above code snippet, AAA is the library containing your transposed dataset, and BBB is the name of the transposed dataset. I just created a macro variable that stores the names of the variables that you want to sort (separated by a comma for use in PROC SQL). Then I created a new table that keeps those columns in that sorted order.
I hope this helps!
I just noticed that you tagged this post for help in SAS Enterprise Guide. I have never used EG, so I don't know that what I just told you will be of much help. Hopefully the idea can somehow be incorporated, though.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.