BookmarkSubscribeRSS Feed
tinc
Calcite | Level 5
Hi, hope you can help:

Trying to find out if it’s possible to reorder the output labels from sas E.g. the output I get out at the mo would be (these are just examples, not real variables etc):



.....AF GH SV DK

GH xx xx xx xx

DK xx xx xx xx

SV xx xx xx xx

AF xx xx xx xx



But I need:



....GH DK SV AF

DK xx xx xx xx

SV xx xx xx xx

GH xx xx xx xx

AF xx xx xx xx



Because that’s how it’s presented in our publications. It’s not a big deal, but just means I spend time faffing moving columns around in excel when I sure it could just output it like this straight away. The labels are ones I have defined in proc formats.

would be a massive help if it is possible but not a huge problem if it isn't.

Thanks in advance
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
Are you using PROC EXPORT to get the data into Excel??? Or are you using ODS to send a report to Excel??? If you are using ODS, then what is your procedure of choice (PROC PRINT, PROC REPORT or PROC TABULATE???).

Actually, seeing the "real" data and variables would be of more help than seeing fake data...for example, you have the same 'values' going down the rows as you have for the column headers. How are you getting or generating this data??? Knowing a bit more would be helpful.

cynthia.
Peter_C
Rhodochrosite | Level 12
tinc

there are many ways to re-order columns
possibly there are more ways than programmers
here is a simple 1
data reordered ;
retain GH DK SV AF ;
set original ;
run;
If you don't need or want to avoid the second copy of the information, make the first line
data reordered /view= reordered ;
Then reordered is a view which when referred will return the columns in your GH DK SV AF order.
But before going away with this answer, please respond to Cynthia's questions - her responses may just be far more illuminating.

peterC
Ksharp
Super User
Hi.
Are you to try to use ' notsorted' option in proc format for customizing order of value.


[pre]

proc format;
value fmt(notsorted)
1,2 = 'GH'
3,4 ='DK'
5,6='SV'
7,8='AF'
;
value _fmt(notsorted)
1,2 = 'DK'
3,4 ='SV'
5,6='GH'
7,8='AF'
;

data temp;
input a b;
format a _fmt.;
format b fmt.;
cards;
1 5
2 8
3 6
2 1
8 3
7 2
6 4
;
run;

proc tabulate data=temp;
class a b;
table a,b;
run;
[/pre]



Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1277 views
  • 0 likes
  • 4 in conversation