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
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.
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.
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 ?
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.