I have just [almost] went insane trying to debug my SAS program!! Luckily brighter minds prevailed :smileysilly:. I had added a line of code in a data step, but commented it out via /* */ so that I could test my code without it first, and my previously working code kept giving an error that my array was unreferenced (error: unreferenced array: short_rate.), when it clearly was:
data forecasts_model_5;
set merged_rates_model_5;
/*%let ante_months = %eval(&exante_forecast_months. + 2);*/
array short_rate(14)short_rate_1-short_rate_14;
And when I just highlighted this data step and ran the selection, it ran without error, but when I attempted to run the whole program (this datastep is part of a macro being called by a larger program), I got these unreferenced array errors. After a while of trying to figure out would could be going on, quadruple checking anything that could have possibly changed from the last error-free run to now, and restarting my computer, it was still happening. So at a loss, I've seen SAS do odd things before, so just for the heck of it I deleted the comment line, knowing that obviously shouldn't change anything, and there it goes, it worked! The error discontinued happening with the above code changed to:
data forecasts_model_5;
set merged_rates_model_5;
array short_rate(14)short_rate_1-short_rate_14;
So I just wanted to find out, is this really an intential aspect of SAS, that in some way comments are including as program statements? It seems extremely unintuitive and very far off base from other programming languages because comments are, as a general rule, always ignored by the compiler to allow for natural language explanations things that should not be executed. Or is this some kind of unknown error in SAS? I was just a loss that a commented line was causing an actual run-time error because I have never seen anything like this before in any programming language.
Thanks for your time,
-Ryan
another macro commenting issue - probably not yours - can be seen when using * to comment out macro code.
*%let animal=pig;
will work fine in open code (the %LET is commented), but not inside of a macro
%macro farm;
*%let animal=pig;
%mend farm;
The %LET executes and the * is written by %FARM.
Try running a macro where you comment out code using *; and have an apostrophe in it. I'm sure there's a rule against doing this, but I generally comment this way so I can uncomment/comment out blocks of code.
e.g.
%macro print;
*Don't use apostrophes in comments;
proc print data=sashelp.class;run;
%mend;
%print;
*this will recover your session;
';%mend;
I think you correctly commented the statement, thus have another problem somewhere in your code. Your example matches the recommendation from SAS, i.e.: 32684 - Using comments within a macro
Can you post your full code?
Agree with Art (Tabachneck), the code you have showed should be fine. With that code, do you get the error when you run it in batch? If you can't share the whole code, can you share the log from the step throws the error (with options MPRINT turned on) ?
--Q.
try this
%*let ante_months = %eval(&exante_forecast_months. + 2);
Ah I see. I had already fixed the problem by removing the comment. However, I was interested in why SAS allows comments to cause errors as in standard programming languages a comment is never even compiled. I suppose it was that the apostrophe in the comment/commenting within the macro was the problem. Also, thank you for all of the information, I do appreciate it.
-But still I beg the question, is there a reason why SAS allows comments to be read as program statement & cause an error in the oddly specific case of commenting a single line of code within a macro? Perhaps this is something that should be addressed in a future release of SAS?
Thanks guys!!
-Ryan
AllSoEasy: I don't think you got the message. You didn't have an apostrophe in the comment you showed and, if if you did, the /* */ type of comment would not have been bothered by it.
You likely have a different problem, like an embedded apostrophe in one of the other not recommended (for a macro) comment types, or an incomplete set of /* */ comments.
I would suggest changing all of your comments to the /* */ type, leave the questioned comment in your code and make sure that the code runs. Otherwise, you risk the possibility that an essential line of code is being ignored.
The typical source of error with embedded comments is that they are not balanced like quotes or parentheses. If you add an embedded comment inside an existing embedded comment, your */ ends the initial embedded comment, not the one you added. A simple example:
/* Do not run the DATA step this time
data new;
set old;
/* %let style=Tricky; */
array nums {3} v1-v3;
run;
End of comment ??? */
The original intent was to comment out the entire DATA step. By adding a second embedded comment around the %LET statement, the result is entirely different. The */ after the %LET statement ends the FIRST embedded comment. The /* before the %LET statement is just text, part of the commented out section of code. Your are left with an ARRAY statement as the first uncommented statement.
That doesn't have to be the source of your problem, but it certainly might be.
another macro commenting issue - probably not yours - can be seen when using * to comment out macro code.
*%let animal=pig;
will work fine in open code (the %LET is commented), but not inside of a macro
%macro farm;
*%let animal=pig;
%mend farm;
The %LET executes and the * is written by %FARM.
*IF* the issue is conveniently commenting code within the Enhanced Editor, here is a keyboard trick that works, even with embedded comments:
Highlight a block of code
CNTL+/ puts /* */ comments on every line
CNTL+SHIFT+/ uncomments every line in the highlighted block.
Here is a link to a complete list of shortcuts:
Keyboard Shortcuts within the Enhanced Editor (Windows only)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.