BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
stat11
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Haikuo
Onyx | Level 15

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

Astounding
PROC Star

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.

stat11
Calcite | Level 5

Thank you both!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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