BookmarkSubscribeRSS Feed
Nadiah
Calcite | Level 5

Hello All,

Hope you can help me with below code. I'm using Case When Function in SAS, and I want to combine those two variables to display one output table. My code as below, there's no error when I run the code but the second variable does not produce any data when its run. Is "AND" can be used to combine both variables?

SQL;

CREATE TABLE WORK.ScribeDeadZone1 AS

SELECT t1.SubId,  

as Location,

as ScribeIndex,

as Measurement,

/* SPULaser */

CASE

WHEN EquipmentID = 2825 and 2859 THEN 'KLM11P2'

WHEN EquipmentID = 2827 and 2861 THEN 'KLM11P3'

3 REPLIES 3
Steelers_In_DC
Barite | Level 11

Give an example of the dataset that you have and what you want your output to be.  The way you are writing this doesn't make sense.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its invalid code (assuming equipmentid is numeric):

/* SPULaser */

CASE

WHEN EquipmentID in (2825,2859) THEN 'KLM11P2'

WHEN EquipmentID in (2827,2861) THEN 'KLM11P3'

ELSE "Not found" end as NEW_VARIABLE


By invalid I mean the case doesn't actually create anything as its missing the end as variable.


Tom
Super User Tom
Super User

Put in the implied parenthesis to see why your syntax does not work.

WHEN ( (EquipmentID = 2825) and 2859) THEN 'KLM11P2'

2859 is always TRUE (SAS treats any non-zero value as TRUE).

So you are only testing if EQUIPMENTID is equal to 2825.

Use the IN operator.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1468 views
  • 1 like
  • 4 in conversation