Help using Base SAS procedures

Case Function in SAS

Reply
New Contributor
Posts: 4

Case Function in SAS

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'

Valued Guide
Posts: 860

Re: Case Function in SAS

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.

Super User
Super User
Posts: 7,997

Re: Case Function in SAS

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.


Super User
Super User
Posts: 7,078

Re: Case Function in SAS

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.

Ask a Question
Discussion stats
  • 3 replies
  • 241 views
  • 1 like
  • 4 in conversation