BookmarkSubscribeRSS Feed
0 Likes

SAS code like:  IF A  < B THEN;   shall be flagged. Perhaps incorrect.

 

SAS Software has in some aspects a syntax that is different from other languages.  When users move between different languages, they are more likely to make mistakes. What I suggest is some kind of Very careful syntax checking mode - wherever that is possible,

/ Br Anders

 

 

11 Comments
AndersS
Pyrite | Level 9

Some logic on this page is NOT correct. 3600 seconds = 60 minutes = 1  hours.
I got this protest xxxx 3600 seconds, 

mkeintz
PROC Star

I would take a lot of convincing to think it is a good idea to flag a statement as "possibly incorrect" when it is a meaningful and executable statement.  In the example you provide, one could have:

 

if a<b then;     /*do nothing*/
else if a=b then ans='Y';
else ans='N';

And if the justification is that SAS syntax is different from some other languages, then what language should be the reference point?

 

I know we usually treat SAS as a language, I'm sure its idiosyncracies make it hard for a computer scientist to think of SAS as a language. I often find it beneficial to remind myself to think of SAS as a tool that looks a lot like a computer language - 

SASKiwi
PROC Star

My personal view is that syntax checking is just that - checking for correct syntax. You can easily syntax check in SAS by adding this to the start of your program:

options obs = 0;

 If the SAS log has no error messages then your syntax is good. It doesn't tell you if your logic is correct or good. I would regard - if A < B then; - as syntactically correct but poor coding practice and so would not ever use it myself. I think it would be very difficult to identify potential syntax problems rather than actual syntax errors and in some cases it could be just a matter of opinion. 

Kurt_Bremser
Super User

Please supply a comprehensive list of "perhaps incorrect" statements, so the developers can implement them in the Enhanced Editor.

Spoiler
this exercise will show you the futility of such an undertaking; it is a fact that programmers have to actually think when they do their job.
Kurt_Bremser
Super User

@mkeintz SAS has languages:

  • data step language
  • SQL (two versions in PROC SQL and PROC FEDSQL)
  • DS2
  • MDX (OLAP server)

and probably more I have not thought of. But overall SAS does not have a consistent language (think of the many procedures where options with identical functions have different names)

AndersS
Pyrite | Level 9

Hi! Good suggestion from Kurt Bremser.    Sorry, I do not have this list.   I fully see the problems with it.
I had a customer once who was VERY, VERY, VERY angry at SAS because of this. - SO is it possible rto do anything about it?

 

(Other problems like :  DATA SET mylib. VALUABLEDATA ;  - I solved that Many years ago). 
/Br Anders

ballardw
Super User

I had a customer once who was VERY, VERY, VERY angry at SAS because of this. - SO is it possible rto do anything about it?

Exactly what was the customer "angry" about and why?That SAS allows a "null" instruction?

And what did they want instead? Perhaps the customer was one of the folks that COBOL sort of targeted: people that want code to read like English or other native language and so becomes extremely wordy (and still has weirdness because computers are not people ).

 

I've only programmed something on the order of 20 or so programming languages if including about 12 dialects of BASIC (which by itself had multiple differences of syntax in different places) and whether you count things like FoxPro or other similar scripts as languages (the count may go up). All are different to do different things. Otherwise there wouldn't be that many different languages. Do operating system scripting languages count? Some of those have some very peculiar instructions such as early DOS that limited you to 10 referenced values at core.

 

 

 

 

 

 

 

SASKiwi
PROC Star

@Kurt_Bremser  - some more SAS languages to add to your list:

 

SCL - SAS Component Language

SAS macro language

IML matrix language

SAS/CONNECT scripting language

SAS Data Quality  - Dataflux scripting

AndersS
Pyrite | Level 9

Hi! Generally speaking: I think that it is a good idea to try to flag for "strange programming" or whatever you want to call it.

IF  A < B  THEN;   is one example   another  ... ELSE;

Over the years I have managed to solve some of these problems, other problems not at all.

But, as always it is the users and the developers that chall judge this.

 

So - end of discussion - for my part.

 

Quentin
Super User

Sorry, I'm still curious as to what you see as strange (perhaps I'm too used to the DATA step language).

 

Is it that SAS allows a null statement?  If so, would you be happier with:

 

if a<b then do;
  /*nothing here*/
end;

I have known people who's coding style is to always use DO blocks, as they feel it is clearer.

 

Or is it that SAS has binary logic rather than trinary, so  a < b will be true if a is missing and b is not?

 

Depending on the language someone is coming from, the fact that missing values sort low and that a logical expression involving missing values returns true/false instead of null/unknown will probably be more surprising than the null statement.

 

Agree with others, I'm all for strict syntax checking.  I hope one day SAS will document dsoptions=note2err.  I'm glad you can turn off SAS auotocorrecting typos (see https://blogs.sas.com/content/iml/2017/02/27/pointcounterpoint-misspell-keywords.html ).  But since the syntax is valid SAS code, this shouldn't be flagged or flaggable.  Better to handle in your style guide.