03-12-2018 03:08 PM
I'm looking to reverse the order of all columns in a sas dataset. I believe the best way to do this would be to transpose the column data to be rows and then reorder the rows.
Here is my code:
*Step One; data pre_transpose; set sashelp.class; *set &&dataset&i.. ; _row_ + 1; * Unique identifier ; length _charvar_ $20; * Create 1 character variable ; run; *Step Two --> Is this where I would reverse columns? ; proc transpose data = pre_transpose out = middle (where = (lowcase(_name_) ne '_row_')); by _row_; var _all_; quit;
Here are pictures of my output:
So, would I reverse the column order in the second step or is there a better way of achieving this result?
03-12-2018 03:20 PM
Do something like this
proc sql noprint; select name into :vars separated by ' ' from dictionary.columns where libname="SASHELP" and memname='CLASS' order by varnum descending; quit; %put &vars.; data want; format &vars.; set sashelp.class; run;
03-12-2018 03:23 PM
03-12-2018 03:25 PM
I agree with @draycut in principle, but suggest using retain rather than format. Using format, as such, you'd lose any formats that you had assigned. So, instead, I'd recommend using:
proc sql noprint; select name into :vars separated by ' ' from dictionary.columns where libname="SASHELP" and memname='CLASS' order by varnum descending; quit; data want; retain &vars.; set sashelp.class; run;
That way you don't risk losing anything,
Art, CEO, AnalystFinder.com
03-12-2018 03:33 PM