BookmarkSubscribeRSS Feed
Gary_Z
Fluorite | Level 6

Are the behaviors of the operators in expressions the same for SAS and CASL? 

SAS

https://go.documentation.sas.com/doc/en/lrcon/9.4/p00iah2thp63bmn1lt20esag14lh.htm

 

CASL

https://go.documentation.sas.com/doc/en/pgmsascdc/v_042/caslpg/n1nlmx3yjfv9vrn1xykzhdfu7jgj.htm

 

Do they all work the same way in CASL and SAS consistently and to produce the same results? Can anyone confirm this? 

 

The pages show there are some differences. I'm noticing that in CASL, for example the comparison operator Not Equal to is != but it doesn't work in CASL, it only works with mnemonics like NE, or I need to use the same operator as SAS which is ^=. Has anyone been able to get != to run in CASL? 

12 REPLIES 12
SASKiwi
PROC Star

Can you post an example CASL log of it "not working"? If it's in the documentation, but doesn't work I would regard that as a bug. What Viya version are you using? 

Gary_Z
Fluorite | Level 6

I am using Viya 4.0

 

This doesn't work:

data casuser.cars;
set sashelp.cars;
keep Make Model Origin MSRP Type;
run;
proc cas;
table.fetch /
table = {name="cars",
caslib="casuser",
where = "Type != 'SUV' & MSRP>=75000"};
run;
quit;

 

ERROR: The WHERE clause 'Type != 'SUV' & MSRP>=75000' could not be parsed as written.
ERROR: Syntax error detected on line 2 at column 7. Found =, expecting a name, a quoted string, a numeric constant, a datetime
constant, a missing value, INPUT, PUT.
ERROR: Failure opening table 'cars'
ERROR: The action stopped due to errors.

 It only works with ^= or NE

 

Tom
Super User Tom
Super User

Sounds like the documentation page is wrong.  != is not a valid way to specify the not equal operator.  So don't use it in your code.

 

There is a FEEDBACK link on every documentation page.  Click on that link and give SAS your feedback that the documentation page is wrong about how to code a not equal operator.  They will get back to you very quickly.

Gary_Z
Fluorite | Level 6

I thought so since I had never been able to get != to work, but do you know if there are any other operator differences between SAS and CASL, where the operator works in one but not the other, or should they both be able to use the same operators and produce consistent results? 

Tom
Super User Tom
Super User

I have never seen using BANG (exclamation point) work as meaning NOT in SAS.

 

Perhaps it works in pure CASL code?  But why use it when you can use something that is easier for others to understand.  Such as the NE mnenomic or literally spelling out NOT.

1634  data test;
1635    A=1; B=2;
1636  /* Does nor work in SAS
1637    bang = ! (a = b);
1638  */
1639    caret = a ^= b;
1640    tilde = a ~= b;
1641    mnemonic = a ne b ;
1642    not = not (a = b);
1643  run;

NOTE: The data set WORK.TEST has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds


1644
1645  proc print;
1646  run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

Result

Obs    A    B    caret    tilde    mnemonic    not

 1     1    2      1        1          1        1

 

 

SASKiwi
PROC Star

The SAS language "not equal" operators are listed as these:

SASKiwi_0-1695100624369.png

The exclamation mark isn't included.

 

Gary_Z
Fluorite | Level 6

Yes but it doesn't work for me in CASL either, despite the documentation saying that. I am wondering if there are any differences between the operators in SAS and CASL. 

SASKiwi
PROC Star

If the SAS operators work in CASL (have you tried them?) as listed in my previous message then this is a documentation error. != definitely doesn't work in SAS 9.4. 

Gary_Z
Fluorite | Level 6

The CASL operators documentation page shows != is a valid operator for CASL, but it doesn't show it in SAS 9.4. 

SASKiwi
PROC Star

I know that but have you tried the SAS not equal operators in CASL? I don't have Viya available to try.

Gary_Z
Fluorite | Level 6
Yes I had already tried NE, ~= and ^= which worked.
SASKiwi
PROC Star

In that case the CASL operators doc is in error and should show the same operators as the SAS doc.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 12 replies
  • 1020 views
  • 2 likes
  • 3 in conversation