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

I've googled this issue but I am perplexed by what could be causing it on my end.

 

My code is basically structured like this:

 

%MACRO example(var);

%DO j = 1 %TO 10;

    * <insert code that works here>;

    %IF &var=var1 %THEN
           %DO;
      * <insert code that works here>;
           %END;

    %ELSE %IF &var=var2 %THEN
           %DO;
* <insert code that works here>; %END; *<insert more code that works here>; %IF &var=var1 %THEN %DO;
* <insert code that works here>;
%END; %ELSE %IF &var=var2 %THEN %DO;

* <insert code that works here>;
%END; %END;

%MEND example;


%Example(var1);

It's annoying because I had some previous variation of this macro working before, then I tried to add a chunk of something else and a second parameter which made it stop working.. Now I can't even get it to work with one parameter.

 

The weird thing is that the first %IF-THEN-ELSE statement works fine, it's the second

%ELSE %IF statement that gives me the error..

 

Yet, the structure is exactly the same as the first one?


Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Looking at your pseudo-code, I doubt we can tell you what is wrong. We would need to see the actual code in order to be able to spot the error. Better yet, show us the ACTUAL log from your code, formatted properly so we can read it by clicking on the </> icon and pasting the log (as text) into the window that appears. Do no strip out parts of the log. We need to see the code in the log and the warnings and error messages.

 
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Looking at your pseudo-code, I doubt we can tell you what is wrong. We would need to see the actual code in order to be able to spot the error. Better yet, show us the ACTUAL log from your code, formatted properly so we can read it by clicking on the </> icon and pasting the log (as text) into the window that appears. Do no strip out parts of the log. We need to see the code in the log and the warnings and error messages.

 
--
Paige Miller
UniversitySas
Quartz | Level 8
Okay, it must have been a typo in the second %if-then-else part,
because I typed it up again, and it works now.

sigh. 1 hour wasted.

Thanks though
ballardw
Super User

One thing to be careful of in macros is the style of comment you use. The * <text> ; inside a macro may attempt to execute and things like single quotes ie. * this isn't a good idea; may have interesting results. If the comment is truly a comment not to execute use either the block quote /* <text> */ or the macro quote:  %* <text> ; inside macros.

UniversitySas
Quartz | Level 8
I already accepted an answer, but I realized later that what you're saying was the actual cause of the error.
Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 8130 views
  • 4 likes
  • 3 in conversation