BookmarkSubscribeRSS Feed
kumarnaidu
Calcite | Level 5

Can anyone tell me how to reorder some variables if I am having large number of variables in my data set.

7 REPLIES 7
LinusH
Tourmaline | Level 20

There are lot of threads discussing this issue. Use the search facility to fins them.

Data never sleeps
Ksharp
Super User

Give us an example, then someone will help you .

kumarnaidu
Calcite | Level 5

suppose I am having variables in the order- visit patno pat_initials body_temp1 sbp1 dbp1 pulserate1 body_temp2 sbp2 dbp2 pulserate2

and I want to arrange these variables in the order-patno visit pat_initials body_temp1 body_temp2 sbp1 sbp2 dbp1 dbp2 pulserate1 pulserate2.

It is just an example.

Ksharp
Super User

OK. You can create a format to customize the order of variables.

data have;
input (visit patno pat_initials body_temp1 sbp1 dbp1 pulserate1 body_temp2 sbp2 dbp2 pulserate2) ($);
cards;
1 2 3 4 5 3 4 5 4 3 2 2 2 2 2 2 2 2 2 2 2 2 2 
;
run;
proc sql;
 select name into : list separated by ' '
  from dictionary.columns
   where libname='WORK' and memname='HAVE' and name not in ('visit' 'patno' 'pat_initials')
    order by scan(name,1,' ','d'),input(scan(name,1,' ' ,'kd'),best32.);
quit;
%put &list;
data want;
 retain patno visit pat_initials &list;
 set have;
run;

Ksharp

kumarnaidu
Calcite | Level 5

thanks a lot

shivas
Pyrite | Level 9

Hi Kumar,

You can use length statement(if you define length for particular column it will come first ,if you don't want to change the order then don't define that variable in length statement) or you can use Column  in proc report.

Thanks,

Shiva

MikeZdeb
Rhodochrosite | Level 12

Hi ... one issue with using LENGTH is making sure that the lengths provided for the variables match those already in the data set that is being reordered.  I think that one is safer with the more standard solution that Ksharp proposed, using a RETAIN statement where no attributes of the variables are needed,

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 2185 views
  • 0 likes
  • 5 in conversation