Example: quiz answers

CALL EXECUTE - How and Why

, ;inputdsn$char50.;callexecute( procprint ,,data=1,Ildsnll ; l~~ run; );cards; ;OnemightthinkwearetryingtoexecutePROCPR INTinaDATA step, , , % 6 , ;lengthvar$9fnrt$15;ifn=1thencallexecute ( datatemp;infilein; [Iinput@3 );infilein;inputrectype$charl.@;ifrectyp e= V thendo;inputvar$fmt$;callexecute(varI]fm t);end;elseifr ectype= D thendo;callexecute( ;infileinfirstobs= IIput(~n_,~.)II;run;);stop;end;run; , , SYMPUT containslocalvariables,thenthenew SYMPUT variableisalsolocaltothisenvironmentothe rwisethevariablewillbeputinthefirstlocal environmentencounteredwithlocalvariables , ;inputname$value!$;callexecute( %global llname~l ; II %let Ilnamell= [1valueII ; );cards;abcxyz; ,notcompiletime;henceitisimportanttohide the% , , ; , ,macrosgenerateSAScode,henceitisbetterto useCALLEXECUTE tosendtheshortmessage, invokeamacro , ;mergeerrs(in=w)original;bybaseid;run;pr ocprintdata=w(obs=500);run;%Putseriouser rors-halting;endsas; ;seterrs(obs=1);callexecute( %fatalerr );run;Whath]

CALL EXECUTE: How and Why H. Ian Whitlock, Westat Inc. Abstract CALL EXECUTE is a relatively new DATA step function which interacts with the SAS Macro Facility.

Tags:

  Call, Why and how, Execute, Call execute how and why, Call execute

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of CALL EXECUTE - How and Why

1 , ;inputdsn$char50.;callexecute( procprint ,,data=1,Ildsnll ; l~~ run; );cards; ;OnemightthinkwearetryingtoexecutePROCPR INTinaDATA step, , , % 6 , ;lengthvar$9fnrt$15;ifn=1thencallexecute ( datatemp;infilein; [Iinput@3 );infilein;inputrectype$charl.@;ifrectyp e= V thendo;inputvar$fmt$;callexecute(varI]fm t);end;elseifr ectype= D thendo;callexecute( ;infileinfirstobs= IIput(~n_,~.)II;run;);stop;end;run; , , SYMPUT containslocalvariables,thenthenew SYMPUT variableisalsolocaltothisenvironmentothe rwisethevariablewillbeputinthefirstlocal environmentencounteredwithlocalvariables , ;inputname$value!$;callexecute( %global llname~l ; II %let Ilnamell= [1valueII ; );cards;abcxyz; ,notcompiletime;henceitisimportanttohide the% , , ; , ,macrosgenerateSAScode,henceitisbetterto useCALLEXECUTE tosendtheshortmessage, invokeamacro , ;mergeerrs(in=w)original;bybaseid;run;pr ocprintdata=w(obs=500);run;%Putseriouser rors-halting;endsas; ;seterrs(obs=1);callexecute( %fatalerr );run;Whathappens?]

2 Ifthestepdoesnotstopwiththefirstexecutio noftheSETstatementbecauseERRS isempty,thenthestring ,wehavewritten%IFERRS isnotempty%then%FATALERR;Whenthemacroexe cutes,itfirstgeneratesthecodefortheDATA step,andthencodeforthePROCPRINT, , ,themergeandprintstepsarecompiledandexec uted, ,asaresultofexecutingamacroviaCALLEXECUT E, ,compiled,andthen2executed, ,butimportant, , , ,alotofthetimeitdoesn run; ,andweusedCALLEXECUTE inthefollowingway:data_null_;inputdsn$ch ar50callexecute( %letdata= %include repcards; ;.Jldsnl~ ; ,11sas ; MoINCLUDE isnotamacroinstruction! ;henceattheendofexecutionthevalueof& (data=);procprintdata= run;%mendprintit;usingdata_null_;inputds n$char50.)

3 ;callexecute( %printit(data= 1 IdsnII ) );cards; ;HeretheparameterDATA isresolvedduringexecutionofthemacro, :YOmacroml(p);data_null_;p=&p;q=symget( p );put %MI: p=q=;run;O/Omendml;Directinvocation%Ml(1 )producesthemessage%Ml:p=lq= :data_null_;callexecute( %MI(1) );run;eitherproducestheerrormessage, NOTE:InvalidargumenttofunctionSYMGET atline1column39. , P=&P; generatedtheline P=1; Q=SYMGET( P ); ;henceitwasafterthemacroMlcompletedexecu tion(duringtheinvokingDATA step).ButPwasaparameterofMl;henceitnolon gerexistedwhentheline Q=SYMGET( P ); slifeendedwhenthemacroMlfinishedgenerati ngcode,butthegeneratedDATA stepexecutedaftertheCALLEXECUTE stepfinished, , ,thiswouldprobablyproducethewrongvalue, , tthinkso, :%macrom2(data=)%localcommvar;data_null_ ;callsymput( commvar stop;set&datanobsrun;1 Jnobs);=nobs;%if&commvar=O%then%do;/ errorprocessing 1%end;%else%do;1 normalprocessing 1%enci;%mendm2; , , ,the ,itistheassignmentthatisdelayed, ,thereareotherwaystoassignmacrovariables whichrequireSASexecution(asopposedtomacr oexecution).

4 Consider%macrom3(data=,var=);procsql;sel ect&varfrom %putsqlobs= quit;%mendm3;Againonemustrememberthatwhe nM3isinvokedviaCALLEXECUTE theexecutionofthePROCSQL codewillbedelayeduntilaftertheDATA stepmakingtheCALLEXECUTE finishes,butthatthe @


Related search queries