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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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