BookmarkSubscribeRSS Feed
SamJse
Calcite | Level 5

Hi,

I have a long code starting with %macro ending with %mend (a long macro) which includes some %do and %if and other statements. I want to run it without macro. So i have removed %macro from the top and %mend from the bottom. As you can guess i get some errors on %do and %if and other syntaxs. 

 

Anyone has an idea how can i fix it?

 

appreciate it.

8 REPLIES 8
ballardw
Super User

Why don't you want to run it as it is?

 

Without seeing specific code and the bits you want to run this question is extremely vague.

 

Depending on the version of SAS you run the %if%do/%end blocks have to be inside a macro as well.

So which version are you using? And the versions that do allow %if/%do/%end will still have limits as to which other macro statements are allowed in open code.

SamJse
Calcite | Level 5

It is SAS 7.1

 

I inherited a macro file, so i have to deal with it anyway.

I would like to run the code without macro but there are some %do %if statements inside, aaah. 

andreas_lds
Jade | Level 19

@SamJse wrote:

It is SAS 7.1

 

I inherited a macro file, so i have to deal with it anyway.

I would like to run the code without macro but there are some %do %if statements inside, aaah. 


I am almost sure, that you don' have SAS 7.1, maybe you are using Enterprise Guide 7.1 ...

I don't understand, why you want to strip the macro-code of working program.

Astounding
PROC Star
Take a look at the options MFILE and MPRINT. In combination, they let you run the program as is (with macro language) and save the resulting SAS program in a file of your choice (with no macro language). At that point you will have a no-macro-language program with the identical logic to work with.
ChrisNZ
Tourmaline | Level 20

> Anyone has an idea how can i fix it?

You obviously have no idea what you are doing (and that's fine, we all started there).

You want to break a working program and can't provide a justification.

Until you understand how the macro works, it is probably best that you leave it alone.

 

 

Kurt_Bremser
Super User

@SamJse wrote:

 

Anyone has an idea how can i fix it?


If it works, don't fix it. Long-time rule for programmers.

 

Removing macro code can only make sense if the macro does not do anything useful. To determine this, you need to see the code that is created by the macro (OPTIONS MPRINT), and then understand what it is doing. See Maxim 30.

 

If you want help in this, you need to post the macro code and how the macro is called, and, if the code uses datasets, supply those datasets in usable form (data step(s) with datalines). 

Tom
Super User Tom
Super User

@SamJse wrote:

Hi,

I have a long code starting with %macro ending with %mend (a long macro) which includes some %do and %if and other statements. I want to run it without macro. So i have removed %macro from the top and %mend from the bottom. As you can guess i get some errors on %do and %if and other syntaxs. 

 

Anyone has an idea how can i fix it?

 

appreciate it.


So you have a macro definition. Do you have an example of code that actually calls the macro?  The name of the macro is the word right after %MACRO.  To call the macro you place a % in front of the name.  If the macro as parameters defined then supply them inside of () after the name.  Example:

%macro mymac(name); .... %mend ;
%mymac(FRED)

If you want to convert the macro to just a regular program then you will need do what the macro codes inside the macro does.  So for example if there is a %IF statement you will need to decide if you want to use the code from the %THEN branch or the %ELSE branch.  If there is an iterative %DO that say does the same thing 3 times 

%do i=1 %to 3 ;
   ... some SAS code ...
%end;

you would need to copy the code three times and add %LET statements to change the values of the macro variable.

%let i=1;
   ... some SAS code ...
%let i=2;
   ... some SAS code ...
%let i=3;
   ... some SAS code ...

etc.

gamotte
Rhodochrosite | Level 12

Hello,

 

What makes you think it needs to be fixed ?

By removing the macro elements of the program, you make it less generic/reusable.

 

Useless use of the macro languange is frequent but to tell if this is the case here,

you should give examples of the %if and %do statements in your program that

illustrate the problems you want to fix.

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1045 views
  • 5 likes
  • 8 in conversation