sas excels!! - systems seminar consultants excels! - systems seminar ... creating a csv file with...

66
SAS Excels! - Systems Seminar Consultants, Inc. 1 SAS ® Excels!! Gerald Frey 2997 Yarmouth Greenway Drive Madison, WI 53711 (608) 278-9964 www.sys-seminar.com

Upload: hamien

Post on 03-May-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

SAS Excels! - Systems Seminar Consultants, Inc. 1

SAS® Excels!!

Gerald Frey2997 Yarmouth Greenway Drive Madison, WI 53711

(608) 278-9964 www.sys-seminar.com

SAS Excels! - Systems Seminar Consultants, Inc. 2

SAS® Excels!! Exporting HTML to Other Programs

It is very common to send data and report output to Excel or other programs.

Techniques:

• Use File Export Data menu choice from SAS to create a XLS file• Write a data step to create a CSV file that can be imported• Use a macro that does the above• Use ODBC to create a connection to a data source • Use the EXCEL libname engine (SAS 9) to access Excel Data• Use ODS to create a report file ready for import

• as HTML• as CSV• as XML

SAS Excels! - Systems Seminar Consultants, Inc. 3

File Export Facility in Interactive SAS®

Advantages:

• Easy• Almost automatic• Best format is chosen for variables

Disadvantages:

• Not available on all systems• Not available for batch jobs• SAS/Access necessary for file types other than .CSV and .TXT files

SAS Excels! - Systems Seminar Consultants, Inc. 4

File Export Facility in Interactive SAS®

File Extract can convert SAS datasets to various formats.

SAS Excels! - Systems Seminar Consultants, Inc. 5

File Export Facility (continued)

You can choose your input dataset.

SAS Excels! - Systems Seminar Consultants, Inc. 6

File Export Facility (continued)

You can then choose output file type.

SAS Excels! - Systems Seminar Consultants, Inc. 7

File Export Facility (continued)

You can then name the output file.

SAS Excels! - Systems Seminar Consultants, Inc. 8

File Export Facility (continued)

You can save the export statements for later reruns.

SAS Excels! - Systems Seminar Consultants, Inc. 9

File Export Facility (continued)

The resulting worksheet in Excel (Full screen view).

SAS Excels! - Systems Seminar Consultants, Inc. 10

Creating a Custom CSV File in a Data Step

Advantages:

• Very flexible• Runs in all environments• Can be tailored for any dataset• Individual formats can be used

Disadvantages:

• User must know variable names and formats• A different and difficult program for each dataset

SAS Excels! - Systems Seminar Consultants, Inc. 11

Creating a Custom CSV File in a Data Step

A data step with lots of quotes and variables.

GDWD�BQXOOB��������������������� �QR�VDV GV QHHGHG� �VHW�VRIWVDOH������������������� �UHDG�LQSXW�GV �ILOH�F�?WHPS?VRIWVDOH�FVY���� �RXWSXW�IODW�ILOH� �LI�BQB� ��WKHQ����������������� �EHIRUH�ILUVW�UHF �

SXW����1DPH���'LYLVLRQ���<HDUV���6DOHV���([SHQVH���6WDWH��

SXW���QDPH����������������� �SXW�RXW�YDOXHV��� ���GLYLVLRQ������������� �TXRWHG�DQG�FRPPDV ���\HDUV���������������� �EHWZHHQ���������� ���VDOHV��������������H[SHQVH������������VWDWH�������������

UXQ���������������������������� �HQG�RI�VWHS������ �

SAS Excels! - Systems Seminar Consultants, Inc. 12

The Resulting Flat File

Quotes and commas are around field names and values.

�1DPH���'LYLVLRQ���<HDUV���6DOHV���([SHQVH���6WDWH��&+5,6���+������������������������:,���0$5.���+������������������������:,���6$5$+���6������������������������01���3$7���+��������������������������,/���-2+1���+�������������������������:,���:,//,$0���+���������������������������01���$1'5(:���6���������������������������01���%(1-$0,1���6������������������������,/���-$1(7���6������������������������:,���67(9(���+����������������������������:,���-(11,)(5���6�������������������������,/���-2<���6���������������������������:,���0$5<���6����������������������������:,���720���6��������������������������01���%(7+���+��������������������������:,��

SAS Excels! - Systems Seminar Consultants, Inc. 13

Opening With Excel

File Open will convert the CSV file to XLS format while reading.

SAS Excels! - Systems Seminar Consultants, Inc. 14

A Different Approach

The DSD option inserts commas automatically.

GDWD�BQXOOB��������������������� �QR�VDV GV QHHGHG� �VHW�VRIWVDOH������������������� �UHDG�LQSXW�GV �ILOH�F�?WHPS?VRIWVDOH�FVY�GVG�SXW�QDPH�����

GLYLVLRQ�\HDUV��VDOHV��H[SHQVHVWDWH��

UXQ���������������������������� �HQG�RI�VWHS������ �

Notes:• You still need to know the field names.• You don’t get the header record from the previous program.

SAS Excels! - Systems Seminar Consultants, Inc. 15

The Resulting Flat File

The file is similar to before and imports similarly.

&+5,6�+����������������:,�0$5.�+����������������:,6$5$+�6����������������01�3$7�+������������������,/�-2+1�+�����������������:,�:,//,$0�+�������������������01$1'5(:�6�������������������01%(1-$0,1�6����������������,/�-$1(7�6����������������:,�67(9(�+��������������������:,-(11,)(5�6�����������������,/-2<�6�������������������:,�0$5<�6��������������������:,�720�6������������������01�%(7+�+������������������:,�

SAS Excels! - Systems Seminar Consultants, Inc. 16

Creating A CSV File With SSCFLAT Macro

A macro to convert any SAS® dataset to a flat file.

Features:• will convert any SAS dataset• runs under windows, OS/390, UNIX• user does not need to know the contents• can provide a header row with field names• will honor most SAS formats assigned to variables• displays record and byte counts• written and supported by SSC

SAS Excels! - Systems Seminar Consultants, Inc. 17

A SSCFLAT Example

Just name the input and output datasets.

GDWD�VRIWVDOH�HWF�5XQ�

�LQFOXGH�D�?VVFIODW�VDV�

�VVFIODW�PVDVGV VRIWVDOH�PIODWRXW F�?WHPS?VRIWVDOH�FVY�PODEHO <(6�

Notes:• SAS 9 has a new macro called %DS2CSV(data=dsn, csvfile=file)

SAS Excels! - Systems Seminar Consultants, Inc. 18

The Resulting Flat File

The file is similar to before and imports similarly.

�(PSOR\HH�1DPH���'LYLVLRQ���<HDUV���6DOHV���([SHQVH���6WDWH��&+5,6���+������������������:,���0$5.���+������������������:,��6$5$+���6������������������01��3$7���+��������������������,/��-2+1���+�������������������:,���:,//,$0���+���������������������01��$1'5(:���6���������������������01���%(1-$0,1���6������������������,/��67(9(���+����������������������:,��-2<���6���������������������:,��0$5<���6����������������������:,��720���6��������������������01�

SAS Excels! - Systems Seminar Consultants, Inc. 19

SSCFLAT Example under OS/390

��-2%��-2%��;;;;�66&�7(67�06*&/$66 $�06*/(9(/ �������6$6���(;(&�6$6GDWD�VRIWVDOH�

LQILOH��LQSXW��HWF��UXQ��LQF�P\�SURJV�VVFIODW���VVFIODW�PVDVGV VRIWVDOH�PSUHIL[ P\�GDWD���

&UHDWHV�0<�'$7$�62)76$/(�'$7

SAS Excels! - Systems Seminar Consultants, Inc. 20

Accessing Excel using ODBC connection(V8)

Advantages:

• File reference in Windows, can be global.• Can read or reference MANY types of files, not just EXCEL

Disadvantages:

• Extra layer to run thru• ODBC may not be efficient

Notes:• ODBC connections are maintained in the Windows environment.

SAS Excels! - Systems Seminar Consultants, Inc. 21

Using ODBC connections(V8)

• Open the ODBC administrator to manage connections.

Notes:• Select an existing connection or click ADD to create a new connection.

SAS Excels! - Systems Seminar Consultants, Inc. 22

Setup ODBC connections(V8)

• Open the ODBC administrator to manage connections.

Notes:• Select an existing connection or click ADD to create a new connection.• Click on Select workbook to manage data source.

SAS Excels! - Systems Seminar Consultants, Inc. 23

Select Data Source

• Click on the existing workbook and OK to use.

Notes:• To create a new spreadsheet give it a name.

SAS Excels! - Systems Seminar Consultants, Inc. 24

Using the ODBC connection

• Use the ODBC connections in Windows as a File reference in SAS.

OLEQDPH P\RGEF RGEF GVQ H[WHVW�3URF�FRQWHQWV�GDWD P\RGEF�VRIWVDOH�UXQ�

SURF�SULQW�GDWD P\RGEF�VRIWVDOH�UXQ�

SAS Excels! - Systems Seminar Consultants, Inc. 25

The Resulting Contents Report in SAS

Note Lengths are longer than we expect!

7KH�6$6�6\VWHP�������������������������� �7KH�&217(176�3URFHGXUH

'DWD�6HW�1DPH��������0<2'%&�VRIWVDOH 2EVHUYDWLRQV�����������0HPEHU�7\SH����������'$7$���������������9DULDEOHV������ �(QJLQH���������������2'%&���������������,QGH[HV�������� �&UHDWHG���������������������������������2EVHUYDWLRQ�/HQJWK�����/DVW�0RGLILHG���������������������������'HOHWHG�2EVHUYDWLRQV���

�������������������������

$OSKDEHWLF�/LVW�RI�9DULDEOHV�DQG�$WWULEXWHV

�����9DULDEOH����7\SH����/HQ����)RUPDW����,QIRUPDW /DEHO

�����'LYLVLRQ����&KDU���������������������������������'LYLVLRQ�����([SHQVH�����1XP����������������������������������([SHQVH�����1DPH��������&KDU���������������������������������1DPH�����6DOHV�������1XP����������������������������������6DOHV�����6WDWH�������&KDU���������������������������������6WDWH�����<HDUV�������1XP����������������������������������<HDUV

SAS Excels! - Systems Seminar Consultants, Inc. 26

The Starting Excel File

Note Softsale and Softdiv are the worksheet names.

SAS Excels! - Systems Seminar Consultants, Inc. 27

Using the EXCEL Libname engine

Advantages:

• Direct access to EXCEL workbooks• Can create multiple worksheets• Can stored formatted data values

Disadvantages:

• Runs in Windows/UNIX environments• Does not support REPLACE of existing table. (Can create New or Read

existing.)• SAS labels, formats, and lengths are not stored

Notes:• EXCEL libname engine is new in SAS 9.

SAS Excels! - Systems Seminar Consultants, Inc. 28

Libname Options using the EXCEL engine

Read using the EXCEL engine.

/,%1$0( OLEUHI �HQJLQH�QDPH!��SK\VLFDO�ILOH�QDPH!��6$6�$&&(66�HQJLQH�FRQQHFWLRQ�RSWLRQV!��6$6�$&&(66�OLEQDPH�RSWLRQV!��

Assign a Libref to an existing EXCEL workbook in ‘e:\softsale.xls’.

OLEQDPH P\H[FHO H[FHO H�?VRIWVDOH�[OV�

SAS Excels! - Systems Seminar Consultants, Inc. 29

List existing Table worksheet names

Read an existing worksheet and create a new worksheet.

OLEQDPH P\H[FHO H[FHO�H�?VRIWVDOH�[OV�

SURF�FRQWHQWV�GDWD P\H[FHO�BDOOB�QRGV�UXQ��������������������������

SAS Excels! - Systems Seminar Consultants, Inc. 30

The Resulting Report in SAS

Note Worksheets are listed.

7KH�6$6�6\VWHP������������������������7KH�&217(176�3URFHGXUH

'LUHFWRU\/LEUHI 0<(;&(/(QJLQH���������(;&(/3K\VLFDO�1DPH��H�?VRIWVDOH�[OV6FKHPD�2ZQHU���$GPLQ

'%060HPEHU��0HPEHU

���1DPH�������7\SH����7\SH���62)76$/(���'$7$����7$%/(���62)76$/(���'$7$����7$%/(���6RIWGLY����'$7$����7$%/(

SAS Excels! - Systems Seminar Consultants, Inc. 31

Creating a worksheet using EXCEL libname engine

Read an existing worksheet and create a new worksheet.

OLEQDPH P\H[FHO H[FHO�H�?VRIWVDOH�[OV�

GDWD�P\H[FHO�KDUGGLY������������ �QHZ�H[FHO�VKHHW�QDPH� �VHW�P\H[FHO�VRIWVDOH���������� �H[LVWLQJ�ZRUNVKHHW��� �ZKHUH�XSFDVH�GLYLVLRQ� +���� �ILOWHU�LQSXW��������� �

UXQ����������������������������� �HQG�RI�VWHS���������� �

SAS Excels! - Systems Seminar Consultants, Inc. 32

The Resulting Excel File

Note Harddiv is the name of the new worksheet.

SAS Excels! - Systems Seminar Consultants, Inc. 33

Creating a worksheet using EXCEL libname engine

Read an existing worksheet and create a new worksheet.

OLEQDPH P\H[FHO H[FHO�H�?VRIWVDOH�[OV�

GDWD�P\H[FHO�KDUGGLY������������ �QHZ�H[FHO�VKHHW�QDPH� �VHW�P\H[FHO�VRIWVDOH���������� �H[LVWLQJ�ZRUNVKHHW��� �ZKHUH�XSFDVH�GLYLVLRQ� +���� �ILOWHU�LQSXW��������� �IRUPDW�VDOHV�GROODU����������� �VHW�IRUPDW����������� �

UXQ����������������������������� �HQG�RI�VWHS���������� �

SAS Excels! - Systems Seminar Consultants, Inc. 34

The Resulting Excel File

Note Sales values are stored as Formatted values.

SAS Excels! - Systems Seminar Consultants, Inc. 35

Sending Reports to Excel With ODS

Advantages:

• Probably the easiest way to get reports to Excel (and other programs)• Available on all platforms both in batch or interactively• ODS captures reports• Excel can capture the data shown on the ODS report• Output will look nice in Excel and others

Disadvantages:

• File sizes can get large if reports are large.

SAS Excels! - Systems Seminar Consultants, Inc. 36

Sending Reports to Excel With ODS

Since Excel automatically converts HTML to XLS format during File Open, to send any SAS® report to Excel:

1. Creating a CSV file with ODS or2. Create a HTML file with ODS or3. Create a XML file with ODS

Then:

4. Use Excel File Open to read the CSV, HTML or XML file5. Format as required in Excel6. Use Excel File Save As to specify XLS format.

SAS Excels! - Systems Seminar Consultants, Inc. 37

A Typical Report

PROC TABULATE produces a table.

SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��

SAS Excels! - Systems Seminar Consultants, Inc. 38

The Current Text Report

How can we get this report into a worksheet?

6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ

edddddddddddddddddfdddddddddddddddddddddddddfdddddddddddddddddddddddddgc�����������������c��������'LYLVLRQ���������c��������'LYLVLRQ cc�����������������hddddddddddddfddddddddddddiddddddddddddfddddddddddddjc�����������������c�����+������c�����6������c�����+������c��� 6������cc�����������������hddddddddddddiddddddddddddiddddddddddddiddddddddddddjc�����������������c���6DOHV����c���6DOHV����c��([SHQVH���c��([SHQVH���cc�����������������hddddddddddddiddddddddddddiddddddddddddiddddddddddddjc�����������������c����6XP�����c����6XP�����c����6XP�����c��� 6XP�����chdddddddddddddddddiddddddddddddiddddddddddddiddddddddddddiddddddddddddjc6WDWH������������c������������c������������c������������c��� chdddddddddddddddddj������������c������������c������������c��� cc,/���������������c������������c������������c������������c��� ������chdddddddddddddddddiddddddddddddiddddddddddddiddddddddddddiddddddddddddjc01���������������c������������c������������c������������c��� �������chdddddddddddddddddiddddddddddddiddddddddddddiddddddddddddiddddddddddddjc:,���������������c������������c������������c������������c��� �������ckdddddddddddddddddlddddddddddddlddddddddddddlddddddddddddlddddddddddddm

SAS Excels! - Systems Seminar Consultants, Inc. 39

Creating A CSV file using ODS

ODS CSVALL destination produces a file.

RGV OLVWLQJ�FORVH�RGV FVYDOO ERG\ F�?WHPS?WDEXODWH�FVY�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV FVY FORVH�RGV OLVWLQJ�

Notes: The CSVALL destination is new in SAS 9.

SAS Excels! - Systems Seminar Consultants, Inc. 40

The Resulting Spreadsheet

Opening the file(1kb) shows:

Notes: There may be some formatting issues, for example: the title is dropped and some column headings are shifted.

SAS Excels! - Systems Seminar Consultants, Inc. 41

Example of Exporting HTML to Excel

Route the report to an HTML file.

RGV OLVWLQJ�FORVH�RGV KWPO�ERG\ F�?WHPS?WDEXODWH�KWPO�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV KWPO�FORVH�RGV OLVWLQJ�

SAS Excels! - Systems Seminar Consultants, Inc. 42

The Resulting Worksheet

The HTML file(6kb) is automatically converted to XLS format.

Notes:Upon using “File Save As”, the worksheet should be saved in XLS format.

SAS Excels! - Systems Seminar Consultants, Inc. 43

Giving the file a XLS extension.

When the file is given XLS as an extension

• The file still contains HTML even though suffix is XLS • Users and Explorer etc. view it as XLS• Excel File Open will automatically opens in XLS format• Excel File Save will automatically save as XLS format

SAS Excels! - Systems Seminar Consultants, Inc. 44

Reducing File Size.

There are several ways to reduce the ODS file size.

• Use the ODS HTML option 67</( 0,1,0$/• Using a custom STYLESHEET(Not covered in this presentation)• ODS PHTML to produce basic HTML • ODS CHTML for compact HTML

SAS Excels! - Systems Seminar Consultants, Inc. 45

STYLE=MINIMAL and a XLS extension.

Reproduce the PROC TABULATE Output.

RSWLRQV�QRFHQWHU�RGV KWPO�ERG\ F�?WHPS?WDEXODWHPLQ�[OV VW\OH PLQLPDO�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV KWPO�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 46

The Resulting Worksheet

Excel has a normal worksheet(3kb).

Notes:• This is probably the easiest way to get any report to Excel• You may have to do some slight formatting

SAS Excels! - Systems Seminar Consultants, Inc. 47

Using ODS PHTML.

Change to use the ODS PHTML destination.

RSWLRQV�QRFHQWHU�RGV SKWPO ERG\ F�?WHPS?WDEXODWHS�[OV�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV SKWPO FORVH�

Notes: PHTML reduces formatting in HTML.• The PHTML destination is experimental in SAS version 8.2.

SAS Excels! - Systems Seminar Consultants, Inc. 48

The Resulting Worksheet

Excel has a normal worksheet(3kb).

Notes:• This is very similar to ODS HTML with Style= minimal

SAS Excels! - Systems Seminar Consultants, Inc. 49

Using ODS CHTML.

If formatting is not required, but saving space is, use the ODS CHTML destination.

RSWLRQV�QRFHQWHU�RGV FKWPO ERG\ F�?WHPS?WDEXODWHF�[OV�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV FKWPO FORVH�

Notes: CHTML produces compact HTML.• The CHTML destination is experimental in SAS version 8.2.

SAS Excels! - Systems Seminar Consultants, Inc. 50

The Resulting Worksheet

Excel has a normal worksheet(2kb).

Notes:• This is very similar to ODS HTML with Style= minimal.

SAS Excels! - Systems Seminar Consultants, Inc. 51

Miscellaneous Notes

• Excel may format things differentlyExample: Leading zeros don’t show.

• Titles may not span columns in the worksheet the way you would like it to- We can Span Columns- Use ODS HTMLCSS

• Use RS=NONE on the HTML statement under OS/390 for a text file:ODS HTML BODY=HTMLOUT STYLE=MINIMAL RS=NONE;

Tricks:• Use the colspan HTML tag in titles that you want to span• Use style sheets as required for Excel to preserve leading zeros

SAS Excels! - Systems Seminar Consultants, Inc. 52

Title Spanning example

• Titles can be forced to span columns.

• In the quoted Title string add HTML tags including colspan=n where n= number of columns to span.

Title Example:

2'6�+70/�ERG\ F�?WHPS?WLWOH�[OV�WLWOH��WG�FROVSDQ �!6RIWVDOH 6DOHV�E\�6WDWH�DQG�

'LYLVLRQ��WG!�SURF�SULQW�GDWD VRIWVDOH�YDU VWDWH�GLYLVLRQ�VDOHV�H[SHQVH�\HDUV�

UXQ�2'6�+70/�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 53

The Resulting Report In Excel(13kb)

Notes: Title starts in cell 2.

SAS Excels! - Systems Seminar Consultants, Inc. 54

HTMLCSS example

• Titles can be forced to span columns.

• In the quoted Title string add HTML tags including colspan=n where n= number of columns to span.

HTMLCSS Example:

2'6�+70/&66 ERG\ F�?WHPS?WLWOH��[OV�WLWOH�6RIWVDOH 6DOHV�E\�6WDWH�DQG�'LYLVLRQ�SURF�SULQW�GDWD VRIWVDOH�YDU VWDWH�GLYLVLRQ�VDOHV�H[SHQVH�\HDUV�

UXQ�2'6�+70/&66 FORVH�

Notes: The ODS HTMLCSS destination produces HTML that refers to Cascading Style Sheets.

• The HTMLCSS destination is experimental in SAS version 8.2.

SAS Excels! - Systems Seminar Consultants, Inc. 55

The Resulting Report In Excel(6kb)

Notes: Title starts in cell 1.

SAS Excels! - Systems Seminar Consultants, Inc. 56

Preserving Leading Zeros into Excel

For Office 97:

2'6�+70/�ERG\ F�?WHPS?3URF3ULQW�[OV�VW\OH PLQLPDO�WLWOH��WG�FROVSDQ �!6RIWVDOH 6DOHV�E\�6WDWH�DQG�

'LYLVLRQ��WG!�SURF�SULQW�GDWD VRIWVDOH�YDU VWDWH�GLYLVLRQ�VDOHV�H[SHQVH�YDU \HDUV���VW\OH ^KWPOVW\OH �YQG�PV�H[FHO�QXPEHUIRUPDW�#�`�

IRUPDW�\HDUV�]���UXQ�2'6�+70/�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 57

Preserving Leading Zeros into Excel

For Excel newer than 97:

2'6�+70/�ILOH F�?WHPS?3URF3ULQW�[OV+HDGWH[W �VW\OH!WG^PVR�QXPEHU�IRUPDW�?#�`��VW\OH!�

WLWOH��WG�FROVSDQ �!6RIWVDOH 6DOHV�E\�6WDWH�DQG�'LYLVLRQ��WG!�

SURF�SULQW�GDWD VRIWVDOH�YDU VWDWH�GLYLVLRQ�VDOHV�H[SHQVH�\HDUV�IRUPDW�\HDUV�]���

UXQ�2'6�+70/�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 58

The Resulting PROC PRINT in Excel 97

SAS Excels! - Systems Seminar Consultants, Inc. 59

HTML from other SAS® Procedures

Try a PROC REPORT to HTML:

RGV KWPO�ERG\ F�?WHPS?3URF5HSRUW�[OV�VW\OH PLQLPDO�WLWOH��WG�FROVSDQ �!6RIWVDOH 6DOHV�E\�6WDWH�DQG�

'LYLVLRQ��WG!�SURF�UHSRUW�GDWD VRIWVDOH QRZG�FROXPQV�VWDWH�GLYLVLRQ�VDOHV�H[SHQVH�GHILQH�VWDWH���JURXS�ZLGWK ��6WDWH�GHILQH�GLYLVLRQ���JURXS�ZLGWK ��6DOHV�'LY��GHILQH�VDOHV���DQDO\VLV�ZLGWK ��

IRUPDW GROODU�����6DOHV�$PW��GHILQH�H[SHQVH���DQDO\VLV�ZLGWK �

IRUPDW FRPPD���([SHQVHV�UXQ��RGV KWPO�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 60

The Resulting PROC REPORT in Excel

Notes:• The Excel worksheet can be modified as you see fit.

SAS Excels! - Systems Seminar Consultants, Inc. 61

Best of both worlds

Create a HTML file and allow the client to view it in a browser, AND still have the option to save it as an Excel file!

We need to create a style using PROC TEMPLATEWe need to create the HTML Report using the style we just created.Then we can display the report in a web browser (HTML) with a button

labeled ‘Download to Excel”.

SAS Excels! - Systems Seminar Consultants, Inc. 62

The Template

Copy an existing style and add the click to save button.

SURF�WHPSODWH�GHILQH�VW\OH�VW\OHV�WHVW�SDUHQW VW\OHV�GHIDXOW�

VW\OH�ERG\�IURP�ERG\��SUHKWPO �LQSXW�

RQFOLFN �GRFXPHQW�H[HF&RPPDQG�6$9($6�WUXH�F�??WHPS??WHVW�[OV����YDOXH ��'RZQORDG�7R�([FHO��

W\SH �EXWWRQ�!�HQG�

UXQ�

Notes: This opens the SAVE AS dialog box. Because we are entering Javascript commands, some quotes and slashes are doubled.

SAS Excels! - Systems Seminar Consultants, Inc. 63

The Template

Now use the changed style to create a HTML report for viewing in a Browser:

RGV KWPO�ILOH oF�?WHPS?FOLFN�KWPOo�VW\OH VW\OHV�WHVW�SURF�WDEXODWH�GDWD VRIWVDOH�WLWOH�6RIWVDOH 6DOHV�DQG�([SHQVHV�E\�'LYLVLRQ�FODVV�VWDWH�GLYLVLRQ��YDU VDOHV�H[SHQVH�WDEOH�VWDWH�GLYLVLRQ VDOHV VXP��

GLYLVLRQ H[SHQVH VXP�UXQ��RGV KWPO�FORVH�

SAS Excels! - Systems Seminar Consultants, Inc. 64

The Resulting HTML REPORT in Web Browser

Opening the HTML file in a Web Browser:

Notes:• The HTML report displays nicely.

SAS Excels! - Systems Seminar Consultants, Inc. 65

The SAVE AS Dialog Box

Clicking on DOWNLOAD TO EXCEL button results:

Notes:• The default location/name was specified in the TEMPLATE.

SAS Excels! - Systems Seminar Consultants, Inc. 66

Questions and Comments?

Gerald Frey

608 278- 9964 x321

gfrey@sys- seminar.com

References:1) The Creative Consultants at Systems Seminar Consultants, Inc.2) “Using ODS to Generate Excel Files”, Chevell Parker,SAS Institute