资源描述:
《writing flexible code with thesas macro facility》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、CHAPTER7WritingFlexibleCodewiththeSASMacroFacility7.1MacroConcepts2107.2SubstitutingTextwithMacroVariables2127.3CreatingModularCodewithMacros2147.4AddingParameterstoMacros2167.5WritingMacroswithConditionalLogic2187.6WritingData-DrivenProgramswithCALLSYMPUT2207.7DebuggingMacroErrors222210TheLitt
2、leSASBook7.1MacroConceptsNotsolongagotheSASmacrofacilitywasconsideredanadvancedtopicrelevantonlytoexperiencedSASusers.Overtime,however,macroshavebecomemoreprevalentsothatnowevennewSASuserswoulddowelltoknowalittleabouttheSASmacrofacility.Fortunately,thebasicmacroconceptsarenotdifficulttoundersta
3、nd.ThischapterintroducesthemostcommonlyusedfeaturesoftheSASmacrolanguage.BecausemacrostakelongertowriteanddebugthanstandardSAScode,yougenerallywon’twantmacrosinprogramsthatwillberunonlyafewtimes.Butusedproperly,macroscanmakethedevelopmentandmaintenanceofproductionprogramsmucheasier.Theydothisin
4、severalways.First,withmacrosyoucanmakeonesmallchangeinyourprogramandhaveSASechothatchangethroughoutyourprogram.Second,macrosallowyoutowriteapieceofcodeonceanduseitoverandover,inthesameprogramorindifferentprograms.Youcanevenstoreprogramsinacentrallocation—anautocalllibrary—andsharethembetweenpro
5、gramsandbetweenprogrammers.Third,youcanmakeyourprogramsdatadriven,lettingSASdecidewhattodobasedonactualdatavalues.ThemacroprocessorWhenyousubmitastandardSASprogram,SAScompilesandthenimmediatelyexecutesit.Butwhenyouwriteamacro,thereisanadditionalstep.BeforeSAScancompileandexecuteyourprogram,SASm
6、ustpassyourmacrostatementstothemacroprocessorwhich“resolves”yourmacros,generatingstandardSAScode.Becauseyouarewritingaprogramthatwritesaprogram,thisissometimescalledmeta-programming.standardmacromacroSASstatementsprocessorstatementsMacrosandmacrovariablesSASmacrocodeconsistsoftwobasicparts:macr
7、osandmacrovariables.Thenamesofmacrovariablesareprefixedwithanampersand(&)whilethe1namesofmacrosareprefixedwithapercentsign(%).Amacrovariableislikeastandarddatavariableexceptthat,havingonlyasinglevalue,itdoesnotbelongtoadataset,and