Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reordering SAS columns for output 1

Status
Not open for further replies.

pruman

Technical User
Aug 7, 2007
1
US
I'm wondering if someone can tell me an easy way to reorder my variable columns in SAS for output to another software package.

Let's say I have columns "a b c d" as a result of working with my data in sas. However, in order to use it in another program, I need columns ordered "d c a b".

I'm sure there's a simple way to do this, but I haven't been able to find it and I just need to move on...

Thanks!
Pruman
 
You can use Proc SQL to do this...
Code:
proc sql;
  create table ordered_out as
  select D
        ,C
        ,A
        ,B
  from disordered_File
  ;
quit;
This is the simplest way to do it.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Hi,

You can simply use a retain statement.
If you have say 50 variables and you are concerned with ordering for only first 5 or 10 columns.
If you use PROC SQL, you have to list all.
With retain statement just use those 5 or 10 variables and you are all set. Using this retain statement on already existing variables never effect the values in these variables.

data ordered_out ;
retain d c a b;
set disordered_File;
run;
 
Great trick, I guess I learn something new everyday. Make sure to put the RETAIN statement before the SET otherwise its doesn't do the trick.
Klaz
 
Sweet...

I went to SAS training last week and this is way better than the answer that I got... which was basically that it couldn't be done in the data step...
 
Did you impress them with your knowledge and tell them how to do it? :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top