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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ArtC
Rhodochrosite | Level 12

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.

View solution in original post

9 REPLIES 9
Reeza
Super User

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;

art297
Opal | Level 21

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?

Quentin
Super User

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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
p12937
Obsidian | Level 7

try this

%*let ante_months =  %eval(&exante_forecast_months. + 2);

AllSoEasy
Obsidian | Level 7

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

art297
Opal | Level 21

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.

Astounding
PROC Star

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.

ArtC
Rhodochrosite | Level 12

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.

jwsquillace
SAS Employee

*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)

SAS(R) 9.3 Companion for Windows

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 3863 views
  • 7 likes
  • 8 in conversation