BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

I am trying to print out an error message (with the red color) in the log if certain conditions are met inside a macro.

The first data step outside of a macro worked as intended, I am able to see the red color error message in the log.

However, I want to achieve the same within the macro, but putlog or %putlog does not work inside the macro, and %put does not print out the error message in the same way as the first data step did.

Can anyone share some insights on how to achieve this? Thanks

 

DATA T;
X = 3;
IF X = 3 THEN putlog "ERROR: this should not happen";
RUN;

%macro T;
DATA T;
X = 3;
%IF X = 3 %THEN %PUT "ERROR: this should not happen ";
RUN;
%mend;
%T;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Why are you using %IF to evaluate DATA variables?

The text X=3 to the macro processor.

 

%macro T;
DATA T;
  X = 3;
  IF X = 3 THEN PUT "ERROR: this should not happen ";
RUN;
%mend;

%T;

If you want to compare the value of a MACRO variable:

 

%let x=3;
%if &x. = 3 %then %do;
   %put ERROR: This is an error message;
%end;

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Rhodochrosite | Level 12

Have you tried getting rid of the quotes with %PUT?

LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

Yes, I realized it didn't work because I had quote around the text. Thanks for the tips! 

ballardw
Super User

Why are you using %IF to evaluate DATA variables?

The text X=3 to the macro processor.

 

%macro T;
DATA T;
  X = 3;
  IF X = 3 THEN PUT "ERROR: this should not happen ";
RUN;
%mend;

%T;

If you want to compare the value of a MACRO variable:

 

%let x=3;
%if &x. = 3 %then %do;
   %put ERROR: This is an error message;
%end;
LL5
Pyrite | Level 9 LL5
Pyrite | Level 9

@ballardw That's great. I know what the issue is - 1)I shouldn't have use quoted to wrap the error message inside the macro. 2)Also, I am not aware we can use %if %then %else outside of a macro, so this is a great discovery for me. 

Lastly, I used %if to evaluate data variable is because I used a bad example to ask this question and I realized it's a bad demonstration.

Thanks for your solution, that's amazing great! 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 359 views
  • 2 likes
  • 3 in conversation