Block Comments starting with an asterisk (*) in SAS files

Syntax highlighting, code folding, brace matching, code indenting, and function list

Block Comments starting with an asterisk (*) in SAS files

Postby Gaël » Thu Jul 20, 2006 7:16 am

The SAS statistical software uses comments in two styles: the usual block comment
Code: Select all
/* */
and additionally
Code: Select all
* ;
(asterisk ... semicolon). Statements are separated by semicolons in SAS. When I define
Code: Select all
Block Comment On Alt = * Block Comment Off Alt = ;
the part of the following expression
Code: Select all
a=b*c;
after the asterisk gets highlighted as a comment, which is clearly wrong. I was unsuccessfull at using Line Comment definitions so far.
How can I fix this?
User avatar
Gaël
Newbie
 
Posts: 2
Joined: Wed Jul 19, 2006 11:00 pm

Re: Block Comments starting with an asterisk (*) in SAS files

Postby Mofi » Thu Jul 20, 2006 11:16 am

Impossible! How should UltraEdit know when * is used as multiplier and when as start of a comment. UltraEdit is a general text editor and not an SAS interpreter. Best you use always /* */.

Or you help UltraEdit's syntax highlighting engine on this bad syntax and use as start of the comment always for example *! and define also *! as alternate block comment on.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Block Comments starting with an asterisk (*) in SAS files

Postby Gaël » Thu Jul 20, 2006 12:57 pm

Danke, Mofi!
It might prove difficult to teach that trick to old programs written by other people... I'll stick to my imperfect solution. I guess only regexp would help in my situation.
User avatar
Gaël
Newbie
 
Posts: 2
Joined: Wed Jul 19, 2006 11:00 pm

Re: Block Comments starting with an asterisk (*) in SAS files

Postby syabiku » Wed Aug 02, 2006 3:51 pm

How about this: I would say that, 95% (or more) of the time, when people use * and ; to define comments in SAS, the * appears in the first column. Maybe it is possible to tell UltraEdit to recognize * as the start of a block comment ONLY when * appears in column 1?
User avatar
syabiku
Newbie
 
Posts: 1
Joined: Tue Aug 01, 2006 11:00 pm

Re: Block Comments starting with an asterisk (*) in SAS files

Postby Mofi » Thu Aug 03, 2006 5:05 am

That's possible for line comments, but not for block comments. The nature of block comments in most program languages is that they can start everywhere and end everywhere whereas there are many program languages which specifies line comments to be valid only in certain columns.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Block Comments starting with an asterisk (*) in SAS files

Postby sssccc » Fri Apr 27, 2012 1:39 pm

I am having the same issue. Although, this thread is over 5 years old but the problem still persists.

Here are my thoughts. I did some research and found there is a Wordfile tag called "Line Comment Preceding Chars". I don't know the exact functionality of this tag but I assume that you can specify what charcters are valid BEFORE a Line Comment symbol which in this case is an asterisk. In SAS, line comment can start with an asterisk in any column provided all preceeding characters on that line are spaces. If the asterisk appears somewhere in middle of the line, then it is not a comment. So, I added the following in my wordfile to include only space and tab as valid character before line comment:

Line Comment Preceding Chars = [ ^t]

I was hoping that only the following line will be highlighted as a comment (asterisk in column 3, not column 1):
Code: Select all
  * THIS IS A COMMENT;

And the following line should not be a comment:
Code: Select all
x=y*z;

My problem is that it still doesn't work as expected.

Can anyone throw some more light why this particular tag not working as intended.

Thanks.
sssccc
Newbie
 
Posts: 8
Joined: Thu Mar 04, 2010 1:53 pm

Re: Block Comments starting with an asterisk (*) in SAS files

Postby Mofi » Sat Apr 28, 2012 4:32 am

Line Comment Preceding Chars = is for line comments and not for block comments. I wrote already once in this topic that block comments can usually occur anywhere in a file in nearly all languages and therefore there are no additional limitations possible like for line comments.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Block Comments starting with an asterisk (*) in SAS files

Postby sssccc » Mon Apr 30, 2012 8:34 am

Hi Mofi,

Thanks for the reply.

I am also referring to Line Comments and not Block Comments. In SAS, Line comments start with an asterisk (*) and block comments start and end with /* and */. For a text to qualify as Line comment, the line must start with an asterisk (in any column). The comment is terminated by SAS line terminator, semicolon. Here is c/p from SAS wordfile:

/L20"SAS 9.1.3" Nocase Line Comment = * Line Comment Preceding Chars = [ ^t] Block Comment On = /* Block Comment Off = */ String Chars = "' DisableMLS File Extensions = SAS LOG.

The bolded entry is what I added. Please let me know if I am interpreting it wrong.

Thanks.
sssccc
Newbie
 
Posts: 8
Joined: Thu Mar 04, 2010 1:53 pm

Re: Block Comments starting with an asterisk (*) in SAS files

Postby Mofi » Mon Apr 30, 2012 10:13 am

The two users above posted that a single asterisk is the beginning of a block comment with a semicolon for marking end of the block comment. That is different to your statement.

However, it is possible to limit interpretation of an asterisk as start of a line comment. But according to help page with title Syntax Highlighting you have to specify a negative character class definition as by default all characters are already valid.

Line Comment Preceding Chars = [~!-~]

worked very well on your example. This expression means all characters except those in hexadecimal range 0x21 (exclamation mark) to 0x7E (tilde) are valid. I have tried also [~!-ÿ] to define the negative character class from decimal range 33 to 255, but for some reason it has not worked. Using any character greater decimal 127 as end of range results in a not working limitation. (Without knowing the code, I know how it looks like because of the observed behavior - the typical signed/unsigned problem on character comparisons.) However, I think that does not matter for SAS files.

The wordfile sas.uew which can be downloaded from IDM extra downloads has been updated accordingly.

PS: I have read now also Overview of the SAS Language - Comments and understand now the problem with asterisk being start of a line respectively block comment ending with a semicolon.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Block Comments starting with an asterisk (*) in SAS files

Postby sssccc » Tue May 01, 2012 10:52 am

Hi Mofi,

That is just perfect. Thank you for a thorough testing and making it work exactly as intended.

On an separate note, it was not just a matter of highlighting of right comment lines but it was affecting other more important functionality of UE. I am referring to "Brace Matching". Without this fix, all text after the astrisk was being treated as comment and UE will not match braces in Comments UNLESS I turn on the option "Brace match in comments", which I would prefer not to do. It was really painful where I had 5 or more sets of braces in one statement.

So, thank you again for all the help.
sssccc
Newbie
 
Posts: 8
Joined: Thu Mar 04, 2010 1:53 pm


Return to Syntax Highlighting