Performance Considerations in SAS Programming Rick Langston · PDF fileTitle: Microsoft...

49
Copyright © 2003, SAS Institute Inc. All rights reserved. Performance Considerations in SAS Programming Rick Langston Manager, Core Systems SAS Institute Inc. [email protected]

Transcript of Performance Considerations in SAS Programming Rick Langston · PDF fileTitle: Microsoft...

Page 1: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

PerformanceConsiderations in SASProgramming

Rick LangstonManager, Core SystemsSAS Institute [email protected]

Page 2: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Features we’ll examine

� Be sure to preload first!

� IF vs. WHERE

� IF-THEN-ELSE

� IF vs. SELECT

� PROC SQL vs. DATA step + sorting

� Using DATA step views

� File I/O vs. Data set I/O

� DIY vs. LSDI

Page 3: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Features we’ll examine

� Stored DATA step programs

� Table look up concerns...

� Traditional merge

� PUT function with format

� New hashing functions

� THREADS discussion using SUMMARY

Page 4: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Be sure to preload first!

������������GDWD�BQXOOB��[ ���UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 5: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

What SAS does for efficiency

� Keeps images in memory

� Doesn’t purge unless low on memory

� But data sets and formats are closed

Page 6: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

IF vs. WHERE

������������GDWD�WHPS��VHW�P\GDWD�[�����������������������LI�PRG�REV��� ������������������UXQ�

127(��7KHUH�ZHUH��������REVHUYDWLRQV�UHDG�IURP������WKH�GDWD�VHW�0<'$7$�;�������127(��7KH�GDWD�VHW�:25.�7(03�KDV��������REVHUYDWLRQV������DQG����YDULDEOHV�127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 7: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

IF vs. WHERE

�����������GDWD�WHPS��VHW�P\GDWD�[�����������������������ZKHUH�PRG�REV��� ������������������UXQ�

127(��7KHUH�ZHUH��������REVHUYDWLRQV�UHDG������IURP�WKH�GDWD�VHW�0<'$7$�;�������������:+(5(�02'�REV���� ��127(��7KH�GDWD�VHW�:25.�7(03�KDV�������������REVHUYDWLRQV�DQG����YDULDEOHV�127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 8: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

IF vs. WHERE

�����������GDWD�WHPS��VHW�P\GDWD�[�������ZKHUH �PRG�REV��� ��������������������UXQ�

127(��7KHUH�ZHUH��������REVHUYDWLRQV�UHDG�IURP�WKH�GDWD�VHW�0<'$7$�;�������������:+(5(�02'�REV���� ��127(��7KH�GDWD�VHW�:25.�7(03�KDV��������REVHUYDWLRQV�DQG����YDULDEOHV�127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 9: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

IF vs. WHERE

� DATA step compiler generates code

� Faster than engine supervisor

� WHERE= may be preferable to WHERE stmt

� ACCESS engines use WHERE efficiently

Page 10: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Setup code for IF/THEN/ELSE

�����������ILOHQDPH�VDVFRGH��WHPS������������ILOHQDPH�VDVFRGH��WHPS������������GDWD�BQXOOB�����������������ILOH�VDVFRGH���SXW�VHOHFW�[��������������������GR�L ��WR������������������������M UDQXQL���������������������������ILOH�VDVFRGH���������������������LI�L!��WKHQ�SXW�HOVH��#��������������������SXW�LI�[� �L��WKHQ��M ����������������������ILOH�VDVFRGH���������������������SXW�ZKHQ��L���M ����������������������HQG�����������������ILOH�VDVFRGH���SXW�RWKHUZLVH��HQG������������������UXQ�

Page 11: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Executing SASCODE1

�����������GDWD�WHPS��VHW�P\GDWD�[������������������������LQFOXGH�VDVFRGH��VRXUFH�������������LI�[� ���WKHQ�M �������������������������HOVH�LI�[� ���WKHQ�M �������������������������HOVH�LI�[� ���WKHQ�M ��������������������������������������HOVH�LI�[� ����WKHQ�M �������������������������HOVH�LI�[� �����WKHQ�M ������������������������������UXQ����127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 12: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Executing SASCODE2

�����������GDWD�WHPS��VHW�P\GDWD�[������������������������LQFOXGH�VDVFRGH��VRXUFH�������������VHOHFW�[��������������ZKHQ����M �������������������������ZKHQ����M ����������������������������ZKHQ�����M �������������������������ZKHQ������M �������������������������RWKHUZLVH��HQG�����������������UXQ����127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 13: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

IF/THEN/ELSE vs. SELECT/WHERE

� SELECT is only slightly better

� Only good with scalar values

� Personal preference and experience

� But don’t forget the ELSE!

Page 14: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

LI�[ ��DQG�\ ��WKHQ�] ��HOVH�LI�[ ��DQG�\ ��WKHQ�] ������

VHOHFW�H[SUHVVLRQ����ZKHQ�YDOXH���������ZKHQ�YDOXH������������

SELECT limitations

Page 15: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

LI�[ ��DQG�\ ��WKHQ�] ��>HOVH@�LI�[ ��DQG�\ ��WKHQ�] ��

LI�[ ��DQG�\ ��WKHQ�] ��>HOVH@�LI�] ��DQG�T ��WKHQ�] ��

To ELSE or not to ELSE....

Page 16: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

SORT vs. SQL

� GDWD�WHPS���VHW�P\GDWD�[�������NHHS REV�[���

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

�����������SURF�VRUW��E\�[��REV�

127(��352&('85(�6257�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

�����������SURF�VRUW�GDWD P\GDWD�[�������NHHS REV�[������������������RXW WHPS���E\�[��REV�

127(��352&('85(�6257�XVHG�������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 17: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

SORT vs. SQL

�����������SURF�VTO�����������������FUHDWH�WDEOH�WHPS��DV�������������������VHOHFW�REV�[��IURP�P\GDWD�[�������������������������RUGHU�E\�[��REV�����������������UXQ���127(��352&('85(�64/�XVHG�������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 18: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

SORT vs. SQL considerations

� Using the SAS engine?

� Other databases may be more efficient

� SORT may be more optimized

� Often, personal preference and experience

Page 19: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Using a VIEW to read from a file

�����������GDWD�IURPILOH�YLHZ IURPILOH�����������������LQILOH�P\GDWD�GDW�����������������LQSXW�[�\�]�����������������UXQ�

������������GDWD�QHZ��VHW�IURPILOH�����������������UXQ�

127(��9LHZ�:25.�)520),/(�9,(:�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 20: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Much better to use SAS data set!

�����������GDWD�QHZ�����������������LQILOH�P\GDWD�GDW�����������������LQSXW�[�\�]�����������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV�������������GDWD�QHZ���VHW�QHZ�����������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 21: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Function vs. hardcoding vs. array...

������������GDWD�QHZ��VHW�P\GDWD�[�����������������������VXP� �VXP�RI�[��[��������������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 22: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Function vs. hardcoding vs. array...

������������GDWD�QHZ��VHW�P\GDWD�[�����������������������VXP� �[��[��[��[��[��[��[��[��[��[�������������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 23: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Function vs. hardcoding vs. array...

�������������GDWD�QHZ��VHW�P\GDWD�[�����������������������DUUD\�[�[��[�������������������VXP� �������������������GR�RYHU�[��������������������VXP���[��������������������HQG�����������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 24: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Which is best?

� Not much performance difference

� Human factor is an issue

� Go with easiest – usually SAS functions

Page 25: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Macro to demonstrate stored programs

ILOHQDPH�VDVFRGH�WHPS��PDFUR�UXQWHVW�GVQDPH�QSDVVHV�QOLQHV��GDWD�BQXOOB��ILOH�VDVFRGH������SXW��GR�QSDVVHV ��WR�QSDVVHV��������SXW�����[ FHLO�UDQXQL������� QOLQHV���������GR�L ��WR�QOLQHV���������SXW�#��LI�[ �L��WKHQ�\ �L�����������HQG������SXW�#��HQG�������SXW�UXQ��GDWD�GVQDPH����LQFOXGH�VDVFRGH�GDWD�GVQDPH��SJP GVQDPH����LQFOXGH�VDVFRGH�GDWD�SJP GVQDPH���H[HFXWH��UXQ��PHQG�

Page 26: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Expansion with 10 IF statements

������������UXQWHVW�QHZ��������035,17�5817(67�����GDWD�BQXOOB�035,17�5817(67�����ILOH�VDVFRGH�035,17�5817(67�����SXW��GR�QSDVVHV ��WR�����035,17�5817(67�����SXW�����[ FHLO�UDQXQL������� ������035,17�5817(67�����GR�L ��WR����035,17�5817(67�����SXW�#��LI�[ �L��WKHQ�\ �L���035,17�5817(67�����HQG�035,17�5817(67�����SXW�#��HQG��035,17�5817(67�����SXW�UXQ��

Page 27: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Actual executed code

035,17�5817(67�����GDWD�QHZ��035,17�5817(67�����GR�QSDVVHV ��WR���035,17�5817(67�����[ FHLO�UDQXQL������� ����035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ���WKHQ�\ ����035,17�5817(67�����HQG�035,17�5817(67�����UXQ�

Page 28: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

035,17�5817(67�����GDWD�QHZ��035,17�5817(67�����GR�QSDVVHV ��WR������

035,17�5817(67�����[ FHLO�UDQXQL������� ����035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ������035,17�5817(67�����LI�[ ���WKHQ�\ ����035,17�5817(67�����HQG�035,17�5817(67�����UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

035,17�5817(67�����GDWD�QHZ��SJP QHZ�����

035,17�5817(67�����GDWD�SJP QHZ��035,17�5817(67�����H[HFXWH�035,17�5817(67�����UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 29: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

035,17�5817(67�����GDWD�QHZ��035,17�5817(67�����GR�QSDVVHV ��WR������035,17�5817(67�����[ FHLO�UDQXQL������� ������

035,17�5817(67�����LI�[ ��WKHQ�\ ���035,17�5817(67�����LI�[ ��WKHQ�\ ������035,17�5817(67�����LI�[ ����WKHQ�\ �����035,17�5817(67�����LI�[ �����WKHQ�\ ������035,17�5817(67�����HQG�035,17�5817(67�����UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

035,17�5817(67�����GDWD�QHZ��SJP QHZ��

035,17�5817(67�����GDWD�SJP QHZ��035,17�5817(67�����H[HFXWH�035,17�5817(67�����UXQ�

127(��'$7$�VWDWHPHQW�XVHG�������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 30: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Stored programs pre-compile macros

������������OHW�P\YDOXH ILUVW������������GDWD�[\]�SJP [\]�����������������[ �P\YDOXH�������������������SXW�[ �����������������UXQ�

�����������GDWD�SJP [\]��UXQ�

[ ILUVW

�������������OHW�P\YDOXH VHFRQG������������GDWD�SJP [\]��UXQ�

[ ILUVW

Page 31: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Setup of key lookup data set

�����������GDWD�FQWOLQ�����������������IPWQDPH WHVWIPW�����������������GR�VWDUW ��WR�������������������������ODEHO SXW�VWDUW�]�����������������������RXWSXW��������������������HQG�����������������UXQ�

Page 32: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Create format - one-time operation

�����������SURF�IRUPDW�FQWOLQ FQWOLQ�127(��)RUPDW�7(67)07�KDV�EHHQ�RXWSXW���������������������������������������UXQ�

127(��352&('85(�)250$7�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 33: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Generate random keys to search

�����������GDWD�NH\WHVW�����������������DUUD\�NH\V�NH\��NH\������������������GR�L ��WR���������������������������GR�RYHU�NH\V�����������������������NH\V FHLO�UDQXQL������� ����������������������������HQG��������������������RXWSXW��������������������HQG�����������������UXQ�

Page 34: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Try first with PUT+FORMAT

�����������GDWD�QHZ�D��VHW�NH\WHVW�����������������NH\�[ SXW�NH\��WHVWIPW�������������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 35: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Traditional sort/merge approach

�����������SURF�VRUW�GDWD NH\WHVW�RXW NH\WHVW[��E\�NH\��

127(��352&('85(�6257�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

�����������GDWD�QHZ�E��PHUJH�NH\WHVW[�LQ ZDQW�FQWOLQ�NHHS VWDUW�ODEHO�UHQDPH �VWDUW NH\���������������������������E\�NH\������������������LI�ZDQW�����������������UXQ�

127(��7KHUH�ZHUH��������REV�UHDG�IURP�:25.�.(<7(67;�127(��7KHUH�ZHUH������REV�UHDG�IURP�:25.�&17/,1�127(��7KH�GDWD�VHW�:25.�1(:�%�KDV��������REV�DQG���YDULDEOHV�127(��'$7$�VWDWHPHQW�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 36: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

You may need an additional sort!

�����������SURF�VRUW�GDWD QHZ�E��E\�L�

127(��352&('85(�6257�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 37: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

What about multiple keys?

�����������GDWD�QHZ�D��VHW�NH\WHVW�����������������NH\�[ SXW�NH\��WHVWIPW�������������������NH\�[ SXW�NH\��WHVWIPW�������������������NH\�[ SXW�NH\��WHVWIPW�������������������UXQ�

Page 38: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Must sort+merge for each key

SURF�VRUW�GDWD NH\WHVW�RXW QHZ�E��E\�NH\��GDWD�QHZ�E��PHUJH�QHZ�E�LQ ZDQW�������������FQWOLQ�NHHS VWDUW�ODEHO�����������������UHQDPH �VWDUW NH\��ODEHO NH\�[���������������E\�NH\�������LI�ZDQW������UXQ�SURF�VRUW�GDWD QHZ�E��E\�NH\�����

Page 39: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Try using indexed data set

�����������GDWD�FQWOLQ[�LQGH[ �VWDUW����VHW�FQWOLQ�

�����������GDWD�QHZ�E��VHW�NH\WHVW�����������������DUUD\�NH\V�NH\��NH\������������������OHQJWK�NH\�[�NH\�[�NH\�[��������������������DUUD\�NH\[�NH\�[�NH\�[�NH\�[�����������������GR�RYHU�NH\V��������������������VWDUW ������OLQN�JHWNH\��BLRUFB ���BHUURUB ���������������������VWDUW NH\V��OLQN�JHWNH\��NH\[ ODEHO��������������������HQG�����������������UHWXUQ������������JHWNH\��VHW�FQWOLQ[�NH\ VWDUW�����������������UHWXUQ�����������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH������������������VHFRQGV

Page 40: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

New HASH object – a contender!

�����������GDWD�QHZ�F��VHW�NH\WHVW�����������������DUUD\�NH\V�NH\��NH\������������������OHQJWK�NH\�[�NH\�[�NH\�[��������������������DUUD\�NH\[�NH\�[�NH\�[�NH\�[�����������������OHQJWK�VWDUW���ODEHO��������������������LI�BQB ��WKHQ�GR��������������������GHFODUH�KDVK�K�KDVKH[S������������������������GDWDVHW��ZRUN�FQWOLQ���RUGHUHG��D���������������������K�GHILQH.H\�VWDUW���������������������K�GHILQH'DWD�ODEHO���������������������K�GHILQH'RQH����������������������HQG�������������������GR�RYHU�NH\V��������������������VWDUW NH\V��UF� �K�ILQG����������������������LI�UF ��WKHQ�NH\[ ODEHO��������������������HQG�����������������UXQ�

127(��'$7$�VWDWHPHQW�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH����������������VHFRQGV������FSX�WLPH�����������������VHFRQGV

Page 41: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Create big test data set

GDWD�WHPS������GR�FY ��WR�������������FODVVYDU FHLO�UDQXQL������� �������������QREV� �FHLO�UDQXQL������� ���������������GR�L ��WR�QREV������������[� �FHLO�UDQXQL������� �����������������\� �[����������������]� �[����������������RXWSXW������������HQG���������HQG������NHHS�FODVVYDU�[�\�]������UXQ�

127(��7KH�GDWD�VHW�:25.�7(03�KDV���������REVHUYDWLRQV�DQG���YDULDEOHV�

Page 42: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Running with NOTHREADS

�����������SURF�VXPPDU\�GDWD WHPS�QRWKUHDGV�����������������FODVV�FODVVYDU�����������������IRUPDW�FODVVYDU�]�������������������YDU�[�\�]�����������������RXWSXW�RXW QHZ��������������������PHDQ P[�P\�P]�PLQ PLQ[�PLQ\�PLQ]��������������������YDU YDU[�YDU\�YDU]�����������������UXQ�

127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH������������������VHFRQGV

Page 43: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Running with THREADS

�����������SURF�VXPPDU\�GDWD WHPS�WKUHDGV�����������������FODVV�FODVVYDU�����������������IRUPDW�FODVVYDU�]�������������������YDU�[�\�]�����������������RXWSXW�RXW QHZ��������������������PHDQ P[�P\�P]�PLQ PLQ[�PLQ\�PLQ]��������������������YDU YDU[�YDU\�YDU]�����������������UXQ�

127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH������������������VHFRQGV

Page 44: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Examining performance difference

� NOTHREADS: 16.32/16.31

� THREADS: 13.93/31.16

� Real time way less than CPU time

� Improved real time

Page 45: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

�����������SURF�VXPPDU\�GDWD WHPS�>WKUHDGV@�>QRWKUHDGV@�����������������FODVV�FODVVYDU���FODVVYDU�������������������IRUPDW�FODVVYDU���FODVVYDU���]������

2Q�8QL[�ER[����XVLQJ�127+5($'6�

127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH������������������������FSX�WLPH�������������������

8VLQJ�7+5($'6�127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH�������������������

2Q�8QL[�ER[����XVLQJ�127+5($'6�

127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH������������������������FSX�WLPH�������������������

127(��352&('85(�6800$5<�XVHG��7RWDO�SURFHVV�WLPH��������UHDO�WLPH�����������������VHFRQGV������FSX�WLPH�������������������

Page 46: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

More on threading

� Need large amounts of data

� Multi-processor machine

� Certain procedures are threaded

� SUMMARY, SORT, TABULATE, GLM

� THREADS/NOTHREADS global option

Page 47: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Summary (not the PROC)

� IF vs. WHERE vs. SELECT

� IF-THEN-ELSE

� PROC SQL

� Watch using views, esp. File I/O

� LSDI: Let SAS Do It!

� Stored programs: big code only

� Table look up: formats, merge, hashing

� Threading

Page 48: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.

Pertinent SUGI papers on performance� SUGI 25: Version 8 Base SAS(r) Performance: How Does It

Stack Up? - Robert Ray

http://www2.sas.com/proceedings/sugi25/25/aa/25p009.pdf

� SUGI 28: An Inside Look at Version 9 and 9.1 Threaded BaseSAS(r) Procedures – Robert Ray

http://www2.sas.com/proceedings/sugi28/282-28.pdf

� SUGI 29: Threads Unraveled: A Parallel Processing Primer,David Shamlin

http://www2.sas.com/proceedings/sugi29/217-29.pdf

Page 49: Performance Considerations in SAS Programming Rick Langston  · PDF fileTitle: Microsoft PowerPoint - RickLangstonperformanceissues.ppt Created Date: 191041123095130

Copyright © 2003, SAS Institute Inc. All rights reserved.Copyright © 2003, SAS Institute Inc. All rights reserved. 49