Help using Base SAS procedures

Conditionally passing control in a program

Reply
Frequent Contributor
Frequent Contributor
Posts: 94

Conditionally passing control in a program

Is there a way to pass the control from one part of the program to another, without the use of macros. I'm looking for something that would do a similar function as a 'go to' statement but is not restricted within one data step only.
Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: Conditionally passing control in a program

Yes, you can use CALL EXECUTE with IF / THEN DO / END logic in a DATA step to cause later processing conditionally. Suggest using the SAS support website for SAS-hosted DOC and supplemental technical / conference reference material.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

call execute data step site:sas.com Message was edited by: sbb
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Conditionally passing control in a program

This is very helpful, thanks Sbb.

I'm wondering if there is any function like the html anchor whereby you can anchor a position in the code. And then once any condition is true, all the code beyond that anchor point can be executed otherwise not.

I understand that macros would make it simple to implement, but could it be done without the use of macros?
Many thanks.
V.
SAS Super FREQ
Posts: 8,868

Re: Conditionally passing control in a program

Hi:
You might investigate the LINK statement:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...

SAS also still supports the GOTO statement -- although generally, I find that GOTO is not needed if you structure your program logic correctly, using DO--ELSE and IF--THEN--DO--ELSE DO--END constructions
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...

And, as Scott says, CALL EXECUTE can place code in the program stack to execute when your "calling" data step program has ended. However, it really depends on what you want to do--CALL EXECUTE can execute program code (such as a PROC STEP) or could, but does not have to, invoke a macro program.

cynthia
Valued Guide
Posts: 2,177

Re: Conditionally passing control in a program

not automatic, but effective:
1 at start point of conditional code open fileref, say, myRef
2 push conditional code to myRef using the file statement MOD option in each subsequent data step
3 once a decision to use the conditional code is made, %include that fileref with code like[pre] data ;
if conditions = ready then do;
call execute( ' %include myRef /source2 ; ' ) ;
end ;
run ;[/pre] the point being that %include in open code will be executed unconditionally, so wrap call execute() around it to apply your conditions.

good luck
peterC
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Conditionally passing control in a program

Very interesting solutions. Many thanks to both of you.
V
Ask a Question
Discussion stats
  • 5 replies
  • 111 views
  • 0 likes
  • 4 in conversation