03-21-2016 04:08 PM
I'm new to SAS. I'm creating a macro where I want to find position of any given character in string using index function.
I'm writing following code but macro stops executing.
%macro check(indata=, char=, var=);
%check(indata=try, char=(, var=value);
it's throwing errors. Not able to figure out whats going wrong
03-21-2016 05:14 PM
The problem is occuring when invoking the macro, since the unbalanced parentheses throw things off. Try quoting the character when you invoke the macro:
%check (indata=try, char=%str(%(), var=value)
In that case, you shouldn't need %BQUOTE any more. Not all characters require quoting, but parentheses do.
03-22-2016 05:01 AM
Firstly, if your new to SAS, I would strongly advise to learn Base SAS which is the programming language. Macro is a tool for generation of text, i.e. it is only there to generate Base SAS code, so if you don't understand Base SAS, you will struggle with Macro. Also, there are specific uses for macro language, using them randomly for purposes creates unweildy hard to mange and QC code which obfuscated. Take your given example below, if you knew Base SAS, you would know that there are plenty of effecient procedures already built into Base SAS which will both be more efficient, and be known to anyone who uses SAS. Your code will be inefficient and obfuscated for other users. Knowing when to use macro is more important than how to use it. The function you want to use here is index: