Hello,
I was just recently using a quite large macro which is used for calculating ratios. After running the macro, I got the following syntax error message:
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE,
GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=. The code inside the macro where the error occurs is the following:
%let p_gen = _p1;
data new;
set old;
...
w725000&p_gen = sum(0, w240000&p_gen, -w239000&p_gen, w239010&p_gen);
...
run; Basically what happens is that SAS does not translate the macro variable properly and adds whitespace before the macro variable.
What SAS should do: w240000_p1
What SAS does: w240000 p1
And obviously that does not really work.
Please tell me the reason behind this strange bug, since the workaround can be quite tedious.
Btw I am working in SAS EG 7.1.
Thanks a lot and kind regards
Paul
This can happen if you used any macro quoting for the variable. With a simple content like
_p1
this should not be necessary.
See this piece of reference code:
options symbolgen;
%let p_gen = _p1;
data test;
xxx&p_gen.yyy = 1;
run;
You can see that you do not get blanks, in the log (no ERROR) and in the dataset.
So it is essential to know what happens between the %LET and the use of the macro variable in the data step.
It looks more like the underscore is being changed to a blank. It does not look like SAS is pre-pending a blank.
It's not normal behavior for SAS to change underscores to blanks. Can you post more of your code? The point at which you have ". . ." may have something going on in it.
How are you determining that SAS is converting the underscore to a space? This isn't normally what SAS does, so I'm wonder if this is really what is happening. Maybe the error message is somehow misleading.
This in particular looks odd to me:
-w239000&p_gen
What is the negative sign doing there? If w239000&p_gen is a variable name, then I would think you would want something like:
(-1 * w239000&p_gen)
Jim
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.