BookmarkSubscribeRSS Feed
vicky07
Quartz | Level 8

Hello,

In the below code I want the test macro to end if syserr is greater than 0 and run the msg macro. In this case the loop doesn't end when the syserr is greater than zero. It executes all the 3 macro parameter  and then leaves  the macro. I am trying to end it as soon as the syserr value becomes greater than zero and run the next macro msg. Any help is much appreciated.

%macro test(dsn);
Data &dsn.;
a = 1;
Run;


%Put syserr ====> &syserr.;
%if &syserr. ne 0 %then %return;
%mend test;
%test(abc);
%test(12ab);
%test(aa);

%macro msg;
  %if &syserr. ne 0 %then %Put "ERROR";
%mend;
%msg;

Thanks!

3 REPLIES 3
LinusH
Tourmaline | Level 20

Not sure what your intentions are, but why don't you just call %msg from %test?

Do also wish to stop the next call to test (aa)? If so, you may need to wrap the %test calls into another macro and do some kind %if logic around the calls.

%msg must be declared before you call %test.

Data never sleeps
vicky07
Quartz | Level 8

I figured the solution. Thanks for your reply.

Domenico
Fluorite | Level 6

Hi,

i guess you got confused with the order of the macros.

Try it this way:

%macro msg;

  %if &syserr. ne 0 %then %do;

      %put syserr ====> &syserr.;

    %put "ERROR";

%end;

%mend;

%macro test(dsn);

%if &syserr. ne 0 %then %return;

data &dsn.;

    a = 1;

run;

%msg;

%mend test;

%test(abc);

%test(12ab);

%test(aa);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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