How to identify an extra semicolon

Reply
Occasional Contributor
Posts: 19

How to identify an extra semicolon

Hi!     If I write      IF A < B then;   B= A;      etc.    B will always be given the value of A - because there is a semicolon directly after THEN.

In other words - SAS does not give any protest or WARNING when the THEN Clause is empty!

My Question: Is there any good way of identifying this problem ?

(except using the Editor and look for   the strings  "THEN;"   and   "THEN ;" )

Br Anders 

Anders Sköllermo
Ph.D., Swedish Actuary

"Both Age and IQ are 69+"
"Retired, But Not Tired"

Sandgränd 13, S-178 40 Ekerö
email: anders.skollermo@one.se
tele: 00468968419 mobil: 0046735077373
Super User
Super User
Posts: 6,502

Re: How to identify an extra semicolon

A lot of SAS programmers adopt a programming style of only one statement per line.  So then seeing more than one semi-colon on the same line would be a warning that there might be an issue.

Occasional Contributor
Posts: 19

Re: How to identify an extra semicolon

Hi! I do agree with Tom, but:

   IF A < B THEN;

   B= A;

- only one semicolon . Still no warning from SAS.

I have been using SAS for many years. I have never made this mistake before, until yesterday.

In my 'program' this a statement that can be taken away.

I think that this is a bug in SAS.

Anders Sköllermo
Ph.D., Swedish Actuary

"Both Age and IQ are 69+"
"Retired, But Not Tired"

Sandgränd 13, S-178 40 Ekerö
email: anders.skollermo@one.se
tele: 00468968419 mobil: 0046735077373
Occasional Contributor
Posts: 19

Re: How to identify an extra semicolon

Hi!
I tried the same problem in SAS MACRO:

%MACRO TEST(A); 

    %IF &A=2 %THEN %PUT OK&A; 

%MEND TEST;

%TEST(2);

%MACRO TESTTHEN(A);

    %IF &A=3 %THEN;

    %PUT OK&A;

%MEND TESTTHEN;

%TESTTHEN(3);

I think that this is a bug in SAS Macro.

Question:   Are there any good ways to identify an extra semicolon ?

Anders Sköllermo
Ph.D., Swedish Actuary

"Both Age and IQ are 69+"
"Retired, But Not Tired"

Sandgränd 13, S-178 40 Ekerö
email: anders.skollermo@one.se
tele: 00468968419 mobil: 0046735077373
PROC Star
Posts: 1,097

Re: How to identify an extra semicolon

I appreciate your point, but I disagree with you.

IF A < B THEN;

is a perfectly valid statement. It means don't do anything if A is less than B. Of course, for it to be useful it would have to be followed by an ELSE, as in

IF A < B THEN; ELSE COMMENT = "A is not less than B";

which of course is equivalent to

IF A >= B THEN; ELSE COMMENT = "A is not less than B";

and it's a sensible response to say that the latter should always be used. However, there are a couple of circumstances where these "no-op" statements occur:

Fairly often, one ends up in a nested set of IF statements, such as

IF A = 1

THEN IF B = 1

           THEN X = 5;

           ELSE;

ELSE X = 6:

where the ELSE; is required to match ELSE X = 6 with IF A = 1.

Another case is where the condition could be:

IF A = 1 THEN X = 5;

without an ELSE clause, but for reasons of clarity and readability it makes more sense to code the condition as the negation, so it becomes

IF /* a condition that makes the most sense stated this way */ THEN;

ELSE /* some actions */;

I know it sounds weird, but I've done it.

My $.02 worth!

  Tom

Ask a Question
Discussion stats
  • 4 replies
  • 252 views
  • 0 likes
  • 3 in conversation