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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 892 views
  • 1 like
  • 4 in conversation