BookmarkSubscribeRSS Feed
SR2019
Calcite | Level 5

Hello All,

 

Is there an easy solution to read in an existing excel and add few columns to that excel in SAS GRID?

 

Thank You,

SR.

5 REPLIES 5
Kurt_Bremser
Super User

There's a variety of methods to get data from Excel into SAS, and then all options to manipulate data that SAS provides are open.

Afterwards, re-export to Excel in form of pure or even formatted data is possible.

 

It all depends on what you have, and what you want to get out of it.

Ksharp
Super User

I do't know if the following code could work.

 

libname x xlsx 'c:\temp\have.xlsx' ;
proc sql;
alter table x.'Sheet1$'n
 add new_variable char(20);
quit;
DWilson
Pyrite | Level 9

@Ksharp wrote:

I do't know if the following code could work.

 

libname x xlsx 'c:\temp\have.xlsx' ;
proc sql;
alter table x.'Sheet1$'n
 add new_variable char(20);
quit;

That doesn't work 🙂

 

 

DWilson
Pyrite | Level 9

@SR2019 wrote:

Hello All,

 

Is there an easy solution to read in an existing excel and add few columns to that excel in SAS GRID?

 

Thank You,

SR.


I'm not sure what you consider easy. This is how I would do it:

1) Read contents of excel file into SAS data set

2) add new variables to SAS data set to represent new columns you want

3) Write out the SAS data set back to Excel, overwriting the existing excel file

 

One drawback to this is that you are overwriting the excel file so you'll lose all the nice formatting and what not included in your excel file.

 

If you are running SAS on a windows PC I think you could create a simple VBSCRIPT that you could run to add columns to excel and preserve the formatting.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @SR2019 

 

Linux SAS cannot handle native Excel file formats, only xlsx-files, and there is no OLE support. But if your spreadsheet is xlsx, you can read xlsx files with proc import or the xlsx libname engine and write them proc export, the xlsx libname engine or ODS the same way as in windows. There is no difference.

 

Usually, the difficult part is to access the files, because spreadsheets normally resides on windows machines in places where the linux system can't see them, so it is necessary to FTP them to linux or move them to a windows folder, that is mounted on the linux system. 

 

If it is not meant for production there is also SAS Enterprise Guide, and for production work there is a SAS PC files server that might make things a little easier, but I have no experience with it and don't miss it, because both FTP and mount works well for us, at least as well as the match between SAS and Excel usually works. These two are not meant for each other!

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1756 views
  • 0 likes
  • 5 in conversation