BookmarkSubscribeRSS Feed
Kody_devl
Quartz | Level 8

Hi All,

 

I have an imported dataset (from a text file) and added only one column to the table / dataset called "Data_Source".  The position of the added column is Last.  How can I move it to First?

 

Columns Order IS:

A    B    C   D   Data_Source

 

Column Order Desired:

Data_Source  A    B    C   D

 

Many Thanks

 

5 REPLIES 5
Loko
Barite | Level 11

hEllo,

 

how have you added the column ? If you have used a data step than you can put it in the first position by simply naming it before the set statement. For example:

 

data want;

length a $ 15;

set sashelp.class;

a='z'||name;

run;
Kody_devl
Quartz | Level 8

Here is my code to add the new column, not in the text file that was imported.

 

 

/* Add Field */

proc sql;

alter table work.Loan_Detail_&i.

add Data_Source CHAR(35);

run;

 

LinusH
Tourmaline | Level 20
There have been quite a few threads with this topic on the communities, pls do a search.
Question is, why bother about column order? Leave that to the reporting part.
Data never sleeps
Kody_devl
Quartz | Level 8

I found some code that works.   Not sure how it works but it move my columns to the front.

 

 

/* Change Order of Fields*/

data work.ALL_MONTHS_LOAN_DETAIL;

retain Source_Date Data_Source;

set ALL_MONTHS_LOAN_DETAIL;

run;

LinusH
Tourmaline | Level 20
That will force a table rewrite, but isn't a problem if it's small.
Another option is to keep an empty template table, with your preferred column order, labels, formats etc. Then append your incoming data to that table.
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 1394 views
  • 5 likes
  • 3 in conversation