DATA Step, Macro, Functions and more

Skip a section of code

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Skip a section of code

Hi,

Is it possible to conditionally skip a section of code?

For example, I have a global macro called VolAdj, which can hold the values Y or N. My code looks like:

          SAS DATA Step....

          SAS DATA Step....


          %macro Zero;

               a few simple calculations;

          %mend;

          %Zero;


           SAS DATA Step...

           SAS DATA Step...

I'd like to write something like:

     if &VolAdj = "Y" then run the macro Zero and the data steps after it;

          else if &VolAdj = "N" then skip the macro Zero and run the data steps after it;


Thank you for any help you can provide!


Accepted Solutions
Solution
‎10-04-2012 03:27 PM
Super User
Posts: 5,083

Re: Skip a section of code

One way to avoid creating a macro just to use %IF/%THEN is to use CALL EXECUTE:

data _null_;

   if "&VolAdj" = "Y" %then call execute('%zero');

run;

If you are putting this sort of code into a DATA step that actually processes data, be careful.  You want to make sure this comparison occurs only once, not once per observation.  There are secondary complications as wlel, but your application seems to be this simple.

Good luck.

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Skip a section of code

Then I guess you need to wrap them up all in macro, then use conditional macro statments to route your code base on conditions, something like %if %then should help.

Haikuo

Solution
‎10-04-2012 03:27 PM
Super User
Posts: 5,083

Re: Skip a section of code

One way to avoid creating a macro just to use %IF/%THEN is to use CALL EXECUTE:

data _null_;

   if "&VolAdj" = "Y" %then call execute('%zero');

run;

If you are putting this sort of code into a DATA step that actually processes data, be careful.  You want to make sure this comparison occurs only once, not once per observation.  There are secondary complications as wlel, but your application seems to be this simple.

Good luck.

Occasional Contributor
Posts: 12

Re: Skip a section of code

Thank you both!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 283 views
  • 3 likes
  • 3 in conversation