Help using Base SAS procedures

Delete rown based on criteria BUT field has both numeric and variable data

Reply
Occasional Contributor
Posts: 15

Delete rown based on criteria BUT field has both numeric and variable data

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?
Frequent Contributor
Frequent Contributor
Posts: 76

Re: Delete rown based on criteria BUT field has both numeric and variable data

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
Occasional Contributor
Posts: 15

Re: Delete rown based on criteria BUT field has both numeric and variable d

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
Occasional Contributor
Posts: 15

Re: Delete rown based on criteria BUT field has both numeric and variable d

I should have used AND.
Problem solved!
Thanks for your time.
Ask a Question
Discussion stats
  • 3 replies
  • 100 views
  • 0 likes
  • 2 in conversation