BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5
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.
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
VD
Calcite | Level 5 VD
Calcite | Level 5
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.
Cynthia_sas
Diamond | Level 26
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
Peter_C
Rhodochrosite | Level 12
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
VD
Calcite | Level 5 VD
Calcite | Level 5
Very interesting solutions. Many thanks to both of you.
V

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1163 views
  • 0 likes
  • 4 in conversation