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,

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
  • 1078 views
  • 0 likes
  • 5 in conversation