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

Hello all,

 

I'm looking for a way to conditionally move to a specific block of code, or end the SAS program all together. I've done all sorts of digging up on the internet, and everyone seems to be pointing the use of a macro wrapper. I've encapsulated my code in a macro wrapper, but it appears SAS EG stops 'recognizing' my code once this happens (as in, everything is greyed out, it's almost like it's been commented out. nothing shows up in the log except for the text itself). From my research, I'm starting to think this may only be for SAS 9.3. At the moment, I am stuck with SAS E Guide 5.1.

 

Ultimately, I want to do this:

%IF DATE() = "&dateVar"d %THEN %goto exit; 

 

(with exit being a label for the last line of the program. I'd also like to consider going to a different part of the code that emails a warning out that the dates in the IF statement did not match.)

 

I hope this first post was descriptive enough. What do the SAS wizards here think?

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

In order to test for a date like you want to do it, you need to wrap the DATE() function with %SYSFUNC() macro function, have a look at the sample code below:

 

%macro sample;
  %let dateVar = 09sep2015;

  %IF %sysevalf( %sysfunc(DATE()) = "&dateVar"d ) = 1 %THEN
    %goto exit;

  %return;
%EXIT:
  %put NOTE: &sysmacroname jumped to EXIT;
%mend;

%sample

The %RETURN statement will end the macro

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

The syntax checker of the enhanced editor is disabled for text within a macro, as a macro can be used to generate parts of code that are complete rubbish at first sight, but will become syntactically correct when the macro is called in the right context.

 

About "wrapping" code:

if you put a macro around existing code to enable the use of %if (which does not work in "open code", ie outside of a macro), you need to call that macro, it won't do anything on it's own:

 

%macro wrap_it;

%if condition %then %do;

/* existing code */

%end;

%mend;

%wrap it;

BrunoMueller
SAS Super FREQ

In order to test for a date like you want to do it, you need to wrap the DATE() function with %SYSFUNC() macro function, have a look at the sample code below:

 

%macro sample;
  %let dateVar = 09sep2015;

  %IF %sysevalf( %sysfunc(DATE()) = "&dateVar"d ) = 1 %THEN
    %goto exit;

  %return;
%EXIT:
  %put NOTE: &sysmacroname jumped to EXIT;
%mend;

%sample

The %RETURN statement will end the macro

JoshS
Fluorite | Level 6

Excellent. Very informational. You and KurtBremser

 

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1563 views
  • 5 likes
  • 3 in conversation