BookmarkSubscribeRSS Feed
osho
Calcite | Level 5
I have a field which has numeric and string data. The values are 1,2,3....10 and 'RP" and 'EX'.

goal: I want to keep only 1 and 2 and delete others.

When I use the following code, it gives me the following error.

code:if status_inventory ne 1 or status_inventory ne 2 then delete;
error: if status_inventory ne 1 or status_inventory ne 2 then delete;

when i use the code by considering it as string data, it deletes all the rows.

any creative ways to handle this?
3 REPLIES 3
LAP
Quartz | Level 8 LAP
Quartz | Level 8
For future reference, it is usually best to include the actual code and the actual error message for clarity.

With that said and assuming that I understand the problem

If status_inventory is a character variable ( and I assume this to be true since you state it can take on the values 1,2,3...10, RP and EX) then your IF statement must put the 1 and 2 in quotes as follows

if status_inventory ne '1' or status_inventory ne '2' then delete
osho
Calcite | Level 5
When I do that, it deletes everything. It is a character variable.


data temp4;
set temp4;
if status_inventory ne '1' or status_inventory ne '2' then delete;
run;

deletes all rows, even when status_inventory takes value 1 and 2
osho
Calcite | Level 5
I should have used AND.
Problem solved!
Thanks for your time.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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