Lorem Ipsum
Lorem Ipsum

Reputation: 4534

Syntax highlighting indicates error where none exists

I am using the Enhanced Editor on Windows.

When I declare a variable within a data set while using a macro variable, the syntax highlighting marks part of it as red. What causes this?

For example,

%let macroVariable = whatever;

data example;
  name_with_&macroVariable. = "Even with the bizarre syntax highlighting, it still worked.";
run;

looks like

syntax highlighting

in the editor.

Running the program does not seemingly generate any errors:

NOTE: The data set WORK.EXAMPLE has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds

It looks like the error originates at the ampersand. According to Names in the SAS Language,

"Special characters, except for the underscore, are not allowed."

Perhaps the editor looks for things on the left hand side of an equal sign to be made only of letters, numbers, and underscores. Anything prior to a character not in one of those sets then gets marked as red.

It looks like I may have answered my own question, but it strikes me as odd that SAS wouldn't account for something which, I would assume, is common place. Is there any danger in using macro variables to name data set variables?

Upvotes: 0

Views: 102

Answers (1)

Joe
Joe

Reputation: 63424

You've run into one of many common issues with the syntax highlighter. Now, technically this may or may not be legal syntax - the highlighter doesn't know if it is valid or not, since it doesn't look at the underlying values.

But yes, I think this should probably be allowed. It also fails to be highlighted correctly in Enterprise Guide, for what it's worth.

Upvotes: 1

Related Questions