Help using Base SAS procedures

How to reorder variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to reorder variables

Hello,

I am looking for a very easy way to custom order variables within a data set.  For example, I have a dataset with variables currently in order x a b y z c

And I would like to reorder them a b c x y z.

I have looked at a few methods (e.g., order=) but they all seem like circuitous methods. What is the easiest way?

Thank you in advance.


Accepted Solutions
Solution
‎08-15-2014 10:21 AM
Trusted Advisor
Posts: 1,228

Re: How to reorder variables

data want;

   retain  a b c x y z;

  set have;

run;

View solution in original post


All Replies
Solution
‎08-15-2014 10:21 AM
Trusted Advisor
Posts: 1,228

Re: How to reorder variables

data want;

   retain  a b c x y z;

  set have;

run;

Occasional Contributor
Posts: 5

Re: How to reorder variables

Perfect, thank you.

Super User
Posts: 10,023

Re: How to reorder variables

proc sql;

create table want as

  select a,b,c,x,y,z  from have;

quit;

Xia Keshan

Occasional Contributor
Posts: 5

Re: How to reorder variables

Within a single variable, is there a way to custom order the outputs in proc freq?

For example;

var1 = c a b

var2 = 1 2 3

proc freq data;

     tables var1*var2;

run;

display such that table outputs as

   1 2 3

a

b

c

Trusted Advisor
Posts: 1,228

Re: How to reorder variables

If I understand it correctly you are looking for a cross tab like this

data have;
input var1 $ var2;
datalines;
a 1
b 2
c 3
;

proc freq data=have;
table var1*var2/nocol norow nopercent ;
run;

Occasional Contributor
Posts: 5

Re: How to reorder variables

I would like to reorder variables within var1.  For example, var1 currently displays as

a  c   b   d

I would like it to display as

a   b   c   d

Occasional Contributor
Posts: 5

Re: How to reorder variables

More precisely, and just focusing on var 1

proc freq data=;

     tables var1;

run;

currently:

a           c              b               d

1           4              5               7

desired:

a           b              c               d

1           5              4               7

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 336 views
  • 0 likes
  • 3 in conversation