BookmarkSubscribeRSS Feed
AndersS
Pyrite | Level 9

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 (Skollermo in English)
4 REPLIES 4
Tom
Super User Tom
Super User

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.

AndersS
Pyrite | Level 9

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 (Skollermo in English)
AndersS
Pyrite | Level 9

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 (Skollermo in English)
TomKari
Onyx | Level 15

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 828 views
  • 0 likes
  • 3 in conversation