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

I am writing a macro with a rather complicated IF statement - however I noticed when I put comments inside I get this annoying error: 


ERROR: There is no matching %IF statement for the %ELSE.

 

I really dont have the option to *not* write comments, is there some other way I can do this?

%global testvar;
%global check;
%let testvar=5;

%MACRO printme(check);

%IF &testvar=1 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=2 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=3 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=4 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=5 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=6 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=7 %THEN
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE %IF &testvar=8 %THEN 
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 
* comment ;
%ELSE
%DO; 
%let check = 1; 
%put testvar is &testvar and check was ✓ 
%END; 

%MEND printme;
%printme;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Macro commenting

 

%*this is my comment;

View solution in original post

3 REPLIES 3
Reeza
Super User

Macro commenting

 

%*this is my comment;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

I have to ask, why are you doing that in macro?  It seems like a large amount of difficult to read, and hard to maintain code, for no apparent benefit.  Use SAS Base - which is designed to process and manipulate data for data processing and manipulation.  Macro is for generating repetitive code, it is not for data processing and manipulation:

%let testvar=5;
data _null_;
  if &testvar. in (1,2,3,4,5,6,7) then call symputx('check',1);
run;
%put testvar. is &testvar. and check was &check.;
JBerry
Quartz | Level 8

Thanks, but this was just a simplified made-up example to illustrate my problem.

 

In reality, what I'm doing involves many macros passing variables back and forth and doing a variety of data tasks, so its quite complicated to post here.

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
  • 1009 views
  • 1 like
  • 3 in conversation