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

Hi All,

I was struggling to make my code works, but two issue hanging on there.  Here is my code:

=================

%MACRO TEST;

  %LET _DEBUG=0;

  %IF &_DEBUG=1 %THEN; %DO;

  %PUT THIS TIME DEBUG IS 1: _DEBUG=&_DEBUG;

  %END;

%MEND TEST;

%TEST;

===============

The output is not I was expecting:

=============

THIS TIME DEBUG IS 1: _DEBUG=0

=============

I changed my code to the following, more severe issue appear:

================

%MACRO TEST2;

  %LET _DEBUG=0;

  %IF &_DEBUG=1 %THEN; %DO;

  %PUT THIS TIME DEBUG IS 1: _DEBUG=&_DEBUG;

  %END;

  %ELSE %DO; 

  %PUT THIS TIME DEBUG IS NOT 1: _DEBUG=&_DEBUG;

  %END;

%MEND TEST2;

%TEST2;

The output is:

==============

90100   %MACRO TEST2;

90101       %LET _DEBUG=0;

90102

90103       %IF &_DEBUG=1 %THEN; %DO;

90104           %PUT THIS TIME DEBUG IS 1: _DEBUG=&_DEBUG;

90105       %END;

90106       %ELSE %DO;

ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.

90107           %PUT THIS TIME DEBUG IS NOT 1: _DEBUG=&_DEBUG;

90108       %END;

90109

90110   %MEND TEST2;

90111

90112   %TEST2;

        -

        180

WARNING: Apparent invocation of macro TEST2 not resolved.

ERROR 180-322: Statement is not valid or it is used out of proper order.

============

Anybody can help me with these two issues?

Thanks in Advance.

Abdu.

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

You don't need a semi colon between your %THEN and %DO.


View solution in original post

2 REPLIES 2
Scott_Mitchell
Quartz | Level 8

You don't need a semi colon between your %THEN and %DO.


Abdu
Calcite | Level 5

Thank you, Scott.  I was screwed by this ";"

Abdu.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 775 views
  • 0 likes
  • 2 in conversation