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!

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

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