BookmarkSubscribeRSS Feed
gbwit
Calcite | Level 5

I have a table like:

id    date                   value       new

x      01/01/2019          1

y      01/01/2019          2

x      01/02/2019          1

z     01/03/2019           1

I am trying to select where id=x,y

Then, once I have that subset, I want to check if x has a corresponding y of the same date -  if it does, then I want to set new to value where y - for both x and y; otherwise, new is just set to value

so the table would become

id    date                   value       new

x      01/01/2019          1             2

y      01/01/2019          2             2

x      01/02/2019          1             1

z     01/03/2019           1             1

 

I am totally unsure how to go about this,

I began by subsetting my data:

 

IF id='x' OR id='y' THEN DO;

/*...*/

END;

ELSE new=value;

 

any help would be appreciated

 

Also, I cannot use the actual dates in my code

2 REPLIES 2
Reeza
Super User
I'm guessing that you also need to generalize this or is this the exact change you need? Why do x and y go together?
gbwit
Calcite | Level 5

I don't need to generalize the id, I know specifically that I need to be comparing/ checking x and y (y is a follow up for x in the data I am using)

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 769 views
  • 0 likes
  • 2 in conversation