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

I have a big report that have 90 columns (I have used proc sql- Combined many datasets finally). 
Is there any way, to move the 60 th and 61st column to the end.
I don't want to list all the columns in the Select Column. Wanted to move only few columns to the end and rest should stay same.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

My error! I hadn't tested the solution.

 

Does it have to be using proc sql? If not, the following data step will work:

data have;
  input col5 col61 col4 col12 col62 col63 col112;
  cards;
1 2 3 4 5 6 7
2 3 4 5 6 7 8
;

data combined;
   set have (drop=col61 col62);
   set have (keep=col61 col62);
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

A report containing 90 variables, would be interested in seeing the code which gets that onto an A4 bit of paper.  Anyways, not a simple method - order of columns in SAS does not matter you see.  What you can do is create a list of all variables except the two you want to move then add those, something like:

proc sql;
  select name 
  into :vlist
  from sashelp.vcolumn
  where name not in ("A","B");
quit;

data want;
  keep=&vlist. A B;
  set yourdata;
run;

However, if your creating one large data from many using select statements, ordering variables at the point would be better rather than moving around at the end.

Kalai2008
Pyrite | Level 9

Appreciate your response.. Thank you.. I will try yours and check if its working.

art297
Opal | Level 21

You could always concatenate the file twice using drop and keep statements. e.g.:

proc sql;
   create table combined as
      select * from have (drop=col61 col62)
      outer union corr
      select * from have (keep=col61 col62)
  ;
 quit;

Art, CEO, AnalystFinder.com

 

Kalai2008
Pyrite | Level 9

Thank you for the solution. The 60th column moved to end but with empty columns. Do you know why is the missing data in the column? I tried removing the CORR too.

art297
Opal | Level 21

My error! I hadn't tested the solution.

 

Does it have to be using proc sql? If not, the following data step will work:

data have;
  input col5 col61 col4 col12 col62 col63 col112;
  cards;
1 2 3 4 5 6 7
2 3 4 5 6 7 8
;

data combined;
   set have (drop=col61 col62);
   set have (keep=col61 col62);
run;

Art, CEO, AnalystFinder.com

 

Kalai2008
Pyrite | Level 9

Thank you.. I already tried that way and it worked.. Thank you so much.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 9299 views
  • 6 likes
  • 3 in conversation