资源描述:
《Leave Your Bad Code Behind_ 50 Ways to Make Your SAS Code Execute More Efficiently》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、PharmaSUG2011-PaperTU04LeaveYourBadCodeBehind:50WaystoMakeYourSASCodeExecuteMoreEfficiently.WilliamEBenjaminJr,OwlComputerConsultancy,LLC,Phoenix,AZAbstract:®Thislaundrylistoftips,gatheredfromover25yearsofSASprogrammingexperience,willshow50waystohelpSASprogrammersmaketheircoderunfasterandmoreefficie
2、ntly.GeneraltopicswillincludedoingmorethanonethingineachDATAstep,combiningstepstomakesimpletaskstakelesscode,usingmacrovariablestosimplifymaintenance,usingbuiltinfeaturesratherthanwritingyourowncode,waystosavediskspace,usingsortsformorethanjustsortingdata,andwaystomaketheprogramcodejustreadbetter(co
3、dethatiseasiertoreadiseasiertomaintain).Thelistisbrokenintocategoriestoallowreaderstofindsomethingtheycanusefaster.Thislistcanworkasaprimerformakingcodechangesthatwillimprovethesystemsandprocessestowhichitisapplied.Keywords:BaseSAS,Codetips,Macrovariables,procedures,conditionalcodeInover25yearsofSAS
4、programmingthisauthorhasencounteredcodeofallshapesandsizes,bothgoodandbad.Allofthecodetipslistedbelowhavebeenusedbytheauthorovertheyearstohelpspeedcode,ormakeitmorereadable.Thetipsaregroupedintoninedifferentgroupstohelplocateatipsbaseduponwhatitisordoestohelptheprogrammer.Forthispapersomeofthetipsha
5、vebeentestedtoseewhichrunsfaster.Thelasttipattheendofthelistisamacrothatsegmentscodeandallowstestingofcodeunitswhilebuildingprograms.Themacrosetsupsegmentsofcodethatcanbeexecutedbysettingswitchestocontrolwhatsegmentsofcodeexecute.ThisworkswellwithTop-Downdevelopmentofaprogrambynotre-runningallofthec
6、odewhiletestingasmallsegmentatthebottom.Ofcoursethiscanalsobedonebyhighlightingcodeandclickingonthe“running-man”;butifyouforgettohighlightthecodetotestandclickthenitallruns.Thetestsweredonebyexecutingthecode11times(6timesthefirstwayand5timesthesecondway).Thefirstexecutionisdiscardedbecauseitisoftenh
7、igherthanalloftheothertests.Apossibleexplanationforthatisthetimerequiredtosetupforthefirstexecutionofthesubmittedcode.ThetestfilewascreatedbyusingtheSASHELP.SHOESdatafileandenlargingthefile.Therecords