BookmarkSubscribeRSS Feed
Santhosh_CHN
Calcite | Level 5

Hi All,

I have two data sets having columns Name, EMPID. Say, one is source and the other is Target and having the same column names. I want these two files to get exported to excel file, at different columns in a same sheet. Say Target needs to be at column A and Source needs to be at column D.

I also want to include a header before these two outputs in excel sheet as Source and Target. How can we do this? Any Help would be appreciated

Thanks,

5 REPLIES 5
Cynthia_sas
SAS Super FREQ

Hi,

  There are several different ways to export your data files to Excel proprietary format: PROC EXPORT and the LIBNAME engine for Excel. You would have to use named ranges to get the output into specific columns, but that means some setup ahead of time to make the named ranges. However, that would not allow you to get the SOURCE and TARGET "headings" that you want.

  On the other hand, you could use ODS destinations to create output for Excel. Getting the output side by side requires that you just use a TITLE statement and one of the ODS destinations that supports creating PANELed output. One such destination is ODS MSOFFICE2K_X, as described here (Base SAS: The MSOffice2K_x Tagset Adds Options to the MSOffice2K Tagset). The example shows 3 tables horizontally, followed by 2 tables, but the general idea is there. You will need to download and install the TAGSETS.MSOFFICE2K_X destination control file (the tagset template), as described here (32394 - Installing and Storing Updated Tagsets for ODS MARKUP). This still doesn't give you the exact control you want (to place something in a fixed starting column), but it does get the output side-by-side.

cynthia

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

hey Cynthia,

you mind giving me a  short example how we can export these  2 datasets to one excel file in 2 different columns with libname engine?

Cynthia_sas
SAS Super FREQ

Hi:

I don't have any examples already written that use named ranges. But I know there are some examples posted on support.sas.com and you can search for them. I believe there were also a lot of papers written about SAS and Excel...a few by Andrea Zimmerman and Harry Droogendyk stick in my mind. The topic should be Google-able.

  But as I indicated, unless you "pre-format" the Excel file to have the "headings" SOURCE and TARGET, you will not be able to write them with SAS.

cynthia

Santhosh_CHN
Calcite | Level 5

Hi &

What I did here is that, I renamed the column names separately like added SRC as prefix to the source attributes and TGT to Target attributes. Then I merged them and exported them to a single file.

,

Thanks for your suggestions.

Regards,

Santhosh

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

yes,i did find a good article by Harry Droogendyk.

Thanks Cynthia

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
  • 2465 views
  • 0 likes
  • 3 in conversation