BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Justin9
Obsidian | Level 7

Can someone help me out with some code that would delete observations where date="31Oct2022"d AND prev_date="31Mar2022"d (i.e. observation only deleted if BOTH conditions are true)?

 

Desired outcome: Delete observations only where date="31Oct2022"d AND prev_date="31Mar2022"d i.e. if only one condition met, keep observations e.g. date="29Apr2022"d / prev_date="31Mar2022"d because only one condition is met

Justin9_0-1668181519635.png

 

When I run the code below, it  deletes observations where date="31Oct2022"d or prev_date="31Mar2022"d for some reason (e.g. in my example above, it deleted the three observations where date="29Apr2022"d / prev_date="31Mar2022"d)  - can someone suggest how I can edit my code to get my desired outcome please?

data test;
       set ac.information_values;
       where (date ne "31Oct2022"d and prev_date ne "31Mar2022"d);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Obvi a problem where the words of explanation don't match the code.

 

If your run the code shown and then "When I run the code below, it deletes observations where date="31Oct2022"d or prev_date="31Mar2022"d for some reason", I consider this impossible, either that's not the code, or your words are wrong.

 

Perhaps you could clear that up.

 

Anyway, what I *think* you want is this:

 

data test;
       set ac.information_values;
       if date="31Oct2022"d and prev_date="31Mar2022"d then delete;
run;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Obvi a problem where the words of explanation don't match the code.

 

If your run the code shown and then "When I run the code below, it deletes observations where date="31Oct2022"d or prev_date="31Mar2022"d for some reason", I consider this impossible, either that's not the code, or your words are wrong.

 

Perhaps you could clear that up.

 

Anyway, what I *think* you want is this:

 

data test;
       set ac.information_values;
       if date="31Oct2022"d and prev_date="31Mar2022"d then delete;
run;

 

--
Paige Miller
Justin9
Obsidian | Level 7
Apologies, my code was supposed to be ne rather than =. Thanks for the code and help!

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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