资源描述:
《Take an In-Depth Look at the %EVAL Function》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、NESUG17Programming&ManipulationTakeanIn-DepthLookatthe%EVALFunctionBeileiXu,Merck&Co.,Inc.,Rahway,NJLeiZhang,Merck&Co.,Inc.,Rahway,NJABSTRACT®%EVALisawidelyusedyetfrequentlymisunderstoodSASmacrolanguagefunctionduetoitsseeminglysimpleform.However,whenitsactualargumentisacomp
2、lexmacroexpressioninterlacedwithspecialcharacters,mixedarithmeticandlogicaloperators,ormacroquotationfunctions,itsusageandresultbecomeelusiveandproblematic.Inthispaper,weaimtoexploreanddemystifytheintricatepartof%EVAL.First,weexplainthemechanismthattheSASmacroprocessorusest
3、oinvoke%EVAL,andpointoutthesubtledifferencebetweentheimplicitandexplicitusesof%EVALcalls.Then,werevealaseriesofhiddenrulesthat%EVALusestomanipulateitsactualmacroargumentembeddedwithdifferenttypesofspecialcharacters.Examplesareprovidedtoillustratethoserulesandexceptionsonaca
4、se-by-casebasis.INTRODUCTIONThe%EVALfunctionevaluatesintegerarithmeticorlogicalexpressions.%EVALoperatesbyconvertingitsargumentfromacharactervaluetoanumericorlogicalexpression.Thenitperformstheevaluation.Finally,%EVALconvertstheresultbacktoacharactervalueandreturnsthatvalue
5、.Allpartsofthemacrolanguagethatevaluateexpressions(forexample,%IFand%DOstatements)call%EVALtoevaluatetheexpressions.UnlikeotherSASmacrofunctions,the%EVALfunctioncanbecalledexplicitlyandimplicitly.Itisoftenoverlookedduetoitsseeminglysimpleimplicitform.Formostserioususers,the
6、%EVALfunctionfrequentlyposeschallenges.Itappearselusiveandproblematicwhenitsargumentisamacroexpressionlacedwithspecialcharacters,mixedarithmeticandlogicaloperators,ormacroquotingfunctions.Considerthefollowingsimpleexample.ThecodeproducestheLOGshownintheboxbelow.*Example1;%m
7、acronotruth(x);%if&x=TRUE%then%putTRUE;%else%putFALSE;%mend;%notruth(TRUE)TRUEInthisexample,the%IFstatementcallsthe%EVALfunctionimplicitlytoevaluatethelogicalexpression&X=TRUE,wherethemacroparameter“X”isresolvedasTRUEbythemacrocall.SinceTRUE=TRUE,theconditionistrue,itwrites
8、TRUEintheLOG.However,youwouldn’texpectthateachofthefollowingmacrocallsalsoproduces