06-01-2013 12:50 PM
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 ;" )
06-01-2013 01:00 PM
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.
06-01-2013 01:27 PM
Hi! I do agree with Tom, but:
IF A < B THEN;
- 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.
06-01-2013 02:10 PM
I tried the same problem in SAS MACRO:
%IF &A=2 %THEN %PUT OK&A;
%IF &A=3 %THEN;
I think that this is a bug in SAS Macro.
Question: Are there any good ways to identify an extra semicolon ?
06-01-2013 03:18 PM
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 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!