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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 437 views
  • 0 likes
  • 2 in conversation