23.12.2014 Views

Methods of Exporting Data to ASCII or EBCDIC - sasCommunity.org

Methods of Exporting Data to ASCII or EBCDIC - sasCommunity.org

Methods of Exporting Data to ASCII or EBCDIC - sasCommunity.org

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong> <strong>to</strong> <strong>ASCII</strong> <strong>or</strong> <strong>EBCDIC</strong><br />

Andrew Wilcox<br />

Amadeus S<strong>of</strong>tware Ltd<br />

Abstract<br />

The SASâ System <strong>of</strong>fers the programmer a multitude <strong>of</strong> ways enabling the<br />

exp<strong>or</strong>tation <strong>of</strong> data from a SAS dataset in<strong>to</strong> <strong>ASCII</strong> / <strong>EBCDIC</strong> text. This paper<br />

discusses some <strong>of</strong> the possible exp<strong>or</strong>t options which are available across the<br />

broad spectrum <strong>of</strong> SAS versions.<br />

Introduction<br />

Eight methods <strong>of</strong> data exp<strong>or</strong>tation are discussed in this paper, Dynamic <strong>Data</strong><br />

Exchange <strong>or</strong> DDE, the Exp<strong>or</strong>t Wizard, the SAS <strong>Data</strong>step, a cus<strong>to</strong>m written exp<strong>or</strong>t<br />

macro, using Proc Print<strong>to</strong>, cut & paste, SAS/ACCESSâ s<strong>of</strong>tware, and a frame<br />

application which uses object linking and embedding technology.<br />

These methods should provide all users, across all platf<strong>or</strong>ms at least two<br />

solutions <strong>to</strong> their exp<strong>or</strong>ting problems.<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

<strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

1) Dynamic <strong>Data</strong> Exchange<br />

DDE is currently only available on Micros<strong>of</strong>t Windows 3.1, 95, NT and f<strong>or</strong> the<br />

SAS System version 6.08 <strong>or</strong> above. To enable exp<strong>or</strong>tation <strong>of</strong> data using DDE the<br />

SAS System and the target application must supp<strong>or</strong>t DDE transmission and both<br />

be active. In this example, inf<strong>or</strong>mation will be passed from a SAS dataset in<strong>to</strong><br />

Micros<strong>of</strong>t Excel 97.<br />

The program below will exp<strong>or</strong>t all the variables held on the DEMOG SAS dataset<br />

in<strong>to</strong> Excel at the following positions: Sheet1, Rows1-Rows16 and Columns1-<br />

Columns16.<br />

Notice that the column names have not been exp<strong>or</strong>ted.<br />

2<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

2) Exp<strong>or</strong>t Wizard<br />

With the SAS System release version 6.12 an interactive method <strong>of</strong> exp<strong>or</strong>ting<br />

data was introduced.<br />

Select Exp<strong>or</strong>t from the File pull down menu :<br />

Enter the name <strong>of</strong> the <strong>Data</strong> Set that you wish <strong>to</strong> Exp<strong>or</strong>t :<br />

Click on<br />

Select the file f<strong>or</strong>mat that you require :<br />

3<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

Click on<br />

Enter the path and name <strong>of</strong> the file in which the exp<strong>or</strong>ted data is <strong>to</strong> be s<strong>to</strong>red :<br />

Click on<br />

The data has been successfully exp<strong>or</strong>ted <strong>to</strong> Excel :<br />

Note:- SAS/ACCESS <strong>to</strong> PC File f<strong>or</strong>mats is required f<strong>or</strong> the exp<strong>or</strong>t wizard <strong>to</strong><br />

create a file in an excel f<strong>or</strong>mat, otherwise a tab <strong>or</strong> comma delimited file can be<br />

created.<br />

4<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

3) DATA STEP<br />

The datastep <strong>of</strong>fers all users <strong>of</strong> the SAS System a method <strong>of</strong> exp<strong>or</strong>ting<br />

inf<strong>or</strong>mation from the SAS System in<strong>to</strong> an external file. However, when exp<strong>or</strong>ting<br />

data from the SAS System you may encounter a problem <strong>of</strong> embedded blanks<br />

within the variables in the SAS dataset. To help the target application imp<strong>or</strong>t the<br />

data successfully a CSV (Comma Separated Values) f<strong>or</strong>mat style could be<br />

selected.<br />

Unf<strong>or</strong>tunately this method f<strong>or</strong> exp<strong>or</strong>ting data will only exp<strong>or</strong>t the ‘data’<br />

p<strong>or</strong>tion <strong>of</strong> the SAS dataset, hence the column headings will not be passed<br />

f<strong>or</strong>ward <strong>to</strong> the target application.<br />

5<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

4) Exp<strong>or</strong>t Macro<br />

This tip enables SAS users on all platf<strong>or</strong>m and SAS versions who do not have the exp<strong>or</strong>t<br />

wizard <strong>to</strong> exp<strong>or</strong>t SAS files as <strong>ASCII</strong> delimited text:<br />

General Syntax:<br />

%send(dataset,delimeter,path,length)<br />

Example:<br />

%send(info.demog , ’ , ’,’c:\rep<strong>or</strong>t.csv’,450)<br />

This will create a CSV file from the INFO.DEMOG SAS dataset allowing a maximum<br />

length <strong>of</strong> 450 characters.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

6<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Resulting in:<br />

7<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

5) Using Proc Print<strong>to</strong><br />

The Print<strong>to</strong> procedure allows the user <strong>to</strong> redirect either the LOG <strong>or</strong> the OUTPUT<br />

window <strong>to</strong> an external <strong>ASCII</strong> file. This procedure is particularly useful due <strong>to</strong> its<br />

simplicity and the fact that it’s available on all platf<strong>or</strong>ms and releases <strong>of</strong> the SAS<br />

System.<br />

Example<br />

Redirect the output window <strong>to</strong> an external <strong>ASCII</strong> file.<br />

The output file contains the following.<br />

etc...<br />

Proc Print<strong>to</strong> Example<br />

OBS GENDER STATUS<br />

1 M S<br />

2 F M<br />

3 M D<br />

4<br />

5<br />

M<br />

F<br />

M<br />

P<br />

6 M S<br />

7 F M<br />

8 F M<br />

9<br />

10<br />

F<br />

F<br />

M<br />

M<br />

8<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

6) Cut and Paste<br />

The ability <strong>of</strong> cutting and pasting from the output window is only available with<br />

Micros<strong>of</strong>t Windows <strong>or</strong> OS/2 and release 6.06 <strong>of</strong> the SAS System <strong>or</strong> above.<br />

Simply highlight the required output, select copy then select paste in the target<br />

application.<br />

Now paste the table.<br />

9<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

7) Using SAS/ACCESS<br />

The SAS/ACCESS product <strong>of</strong>fers users interactive and non-interactive methods<br />

<strong>of</strong> exp<strong>or</strong>ting data in<strong>to</strong> a variety <strong>of</strong> f<strong>or</strong>mats and not just <strong>ASCII</strong> text. This paper will<br />

demonstrate the batch approach <strong>to</strong> SAS/ACCESS, by exp<strong>or</strong>ting a SAS dataset <strong>to</strong><br />

an Excel file.<br />

View the new Excel file.<br />

10<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

8) Object Linking and Embedding (OLE)<br />

SAS/AFâ S<strong>of</strong>tware enables users <strong>to</strong> communicate with other Windows products<br />

as long as they are OLE2 compliant applications. This means that inf<strong>or</strong>mation<br />

can be sent from the SAS system in<strong>to</strong> a specific Cell <strong>of</strong> a spreadsheet, also this<br />

cell may be pre-f<strong>or</strong>matted thereby enabling some dramatic display<br />

enhancements.<br />

Example<br />

On pressing the Exp<strong>or</strong>t but<strong>to</strong>n, OLE now transmits the table from SAS in<strong>to</strong> a<br />

pre-f<strong>or</strong>matted Excel spreadsheet.<br />

Summary<br />

The SAS System provides the programmer with <strong>to</strong>ols <strong>to</strong> help the exp<strong>or</strong>tation <strong>of</strong><br />

data. These <strong>to</strong>ols can be GUI driven like the exp<strong>or</strong>t wizard <strong>or</strong> macro driven.<br />

11<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.


<strong>Methods</strong> <strong>of</strong> <strong>Exp<strong>or</strong>ting</strong> <strong>Data</strong><br />

Contact Inf<strong>or</strong>mation<br />

Andrew Wilcox<br />

Amadeus S<strong>of</strong>tware Ltd<br />

13 C<strong>or</strong>n Street<br />

Witney<br />

OX8 7DB<br />

England<br />

Telephone +44 (0) 1993 775454<br />

Fax +44 (0) 1993 700577<br />

E-mail enquiries@amadeus.co.uk<br />

Web Page www.amadeus.co.uk<br />

Copyright Notice<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any<br />

means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any purpose, without the express written<br />

permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. ã Amadeus S<strong>of</strong>tware. April 1998. All rights<br />

reserved.<br />

Trademark Notice<br />

SAS/ACCESS, SAS/AF are registered trademarks <strong>of</strong> SAS Institute, Cary, NC,<br />

USA.<br />

Micros<strong>of</strong>t Excel is a registered trademark <strong>of</strong> Micros<strong>of</strong>t, Calif<strong>or</strong>nia, USA.<br />

12<br />

No part <strong>of</strong> this material may be reproduced <strong>or</strong> transmitted in any f<strong>or</strong>m <strong>or</strong> by any means, electronic <strong>or</strong> mechanical, f<strong>or</strong> any<br />

purpose, without the express written permission <strong>of</strong> Amadeus S<strong>of</strong>tware Ltd. Ó Amadeus S<strong>of</strong>tware Ltd. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!