资源描述:
《using functions sysfunc and ifc to conditionally execute statements in open code》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、SASGlobalForum2009Coders'CornerPaper054-2009UsingFunctionsSYSFUNCandIFCtoConditionallyExecuteStatementsinOpenCodeRonaldJ.Fehd,CentersforDiseaseControlandPrevention,Atlanta,GA,USAABSTRACTDescription:Thispaperexplainshowtoconditionallyexecutestatementsinopencodewithouthavingtowrapth
2、ecodeinamacro.Thisisaccom-plishedbycombiningthemacrofunctionsysfuncwiththedatastepfunctionifc.Theresultisthatparameterizedincludeprogramsgainthepowerofconditionalprocessing—%if...%then—forwhichmacrosareusuallyused.Purpose:replacementformacroifstatementAudience:advancedusersandmacr
3、oprogrammers.Keywords:assertions,function,ifc,nrstr,parameterizedincludeprogram,sys-funcInformation:assertions,conditionalprocessing,parameterizedincludeprogramsInthispaperThispapercontainsthefollowingtopics.Introduction2FunctionIFC3FunctionSysFunc4SysFuncandIFC4UsageExamples5Call
4、ingRoutines............................6Assertions................................8Conclusion91SASGlobalForum2009Coders'CornerIntroductionOverviewProgramdevelopmentproceedsthroughthesestages:createadhocprogramsidentifyprogramswithsimilaralgorithmsconsolidateintoparameterizedinc
5、ludeprogramwherenecessary,converttomacroforconditionalprocessingThetechniquesshownhereeliminatetheneedformacrosandreplaceconditionalprocessingwithinlinestatements.Example:%ifstatementusedtoconditionallyexecuteblocksofcode.%macroDoThis;%if%then%do;*statementsfortrue;%en
6、d;%else%do;*statementsforfalse;%end;run;%mend;%DoThiscanbereplacedwiththis:%sysfunc(ifc(,*statementsfortrue;,*statementsforfalse;))2SASGlobalForum2009Coders'CornerFunctionIFCDataStepFunctionTheifcfunctionhasfourparameters:IFC1.alogicalexpression2.charactervaluereturnedw
7、hentrue3.valuereturnedwhenfalse4.valuereturnedwhenmissing,whichisoptionalifc-syntax.txt1IFC(logical-expression2,value-returned-when-true3,value-returned-when-false4<,value-returned-when-missing>5)Thisexampleshowsthefunctioninadatastep.ifc-data.sas1DATAWork.TestIfc;2attribNlength=4
8、3Valuelength=$%length(missing);4d