Column Sort

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Column Sort

Dear Community,

 

I have a large SAS data file with many column headings.  Is there a way to sort the dataset by column names?

 

Thank you in advance.

 


Accepted Solutions
Solution
‎04-14-2016 11:39 AM
Trusted Advisor
Posts: 1,204

Re: Column Sort

A small modification in proc sql will give the desired results. Please try this.

 

proc contents data=sashelp.class out=vars;
run;

 

proc sql;
select name into :columns separated by ' ' from vars
order by name;
quit;

 

data want;
retain &columns;
set sashelp.class;
run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: Column Sort

Always better to provide a sample data. May be this is what you are trying to do

 

proc contents data=sashelp.class out=vars;

run;

 

proc sql;
select name into :columns from vars
order by name;
quit;

 

data want;
retain &columns;
set sashelp.class;
run;

Occasional Contributor
Posts: 17

Re: Column Sort

[ Edited ]

Thank you greatly for your help!  

Solution
‎04-14-2016 11:39 AM
Trusted Advisor
Posts: 1,204

Re: Column Sort

A small modification in proc sql will give the desired results. Please try this.

 

proc contents data=sashelp.class out=vars;
run;

 

proc sql;
select name into :columns separated by ' ' from vars
order by name;
quit;

 

data want;
retain &columns;
set sashelp.class;
run;

Occasional Contributor
Posts: 17

Re: Column Sort

Thank you! Your prior solution works too Smiley Happy

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 366 views
  • 0 likes
  • 2 in conversation