BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ct_surg
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want;

   retain  a b c x y z;

  set have;

run;

View solution in original post

7 REPLIES 7
stat_sas
Ammonite | Level 13

data want;

   retain  a b c x y z;

  set have;

run;

ct_surg
Calcite | Level 5

Perfect, thank you.

Ksharp
Super User

proc sql;

create table want as

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

quit;

Xia Keshan

ct_surg
Calcite | Level 5

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

stat_sas
Ammonite | Level 13

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;

ct_surg
Calcite | Level 5

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

ct_surg
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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