Desktop productivity for business analysts and programmers

Move a certain column to the end/beginning without knowing the rest of columns

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

Move a certain column to the end/beginning without knowing the rest of columns

[ Edited ]

Original dataset:

Type Class ... Total ... Category

1. Need to move the column 'Total' to the end without changing the order for the rest of columns.

The result looks like:

Type Class ... Category Total

2. Need to move the column 'Total' to the beginning without changing the order for the rest of columns.

Total Type Class ... Category

Requirements:

Hard-coding like

retain ColA ColB ... ColZ Total;

wouldn't work because we wouldn't know the names for the rest of the columns or how many columns there are (they are dynamic).

 

Thank you.


Accepted Solutions
Solution
‎03-28-2017 10:32 PM
Super User
Super User
Posts: 6,367

Re: Move a certain column to the end/beginning without knowing the rest of columns

Use the KEEP= and/or DROP= dataset options.

data one ;
  set have (drop=Total);
  set have ;
run;

data two;
  set have (keep=Total);
  set have ;
run;

View solution in original post


All Replies
Solution
‎03-28-2017 10:32 PM
Super User
Super User
Posts: 6,367

Re: Move a certain column to the end/beginning without knowing the rest of columns

Use the KEEP= and/or DROP= dataset options.

data one ;
  set have (drop=Total);
  set have ;
run;

data two;
  set have (keep=Total);
  set have ;
run;
Frequent Contributor
Posts: 80

Re: Move a certain column to the end/beginning without knowing the rest of columns

That's super smart! Thank you.
☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 166 views
  • 1 like
  • 2 in conversation