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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 589 views
  • 0 likes
  • 2 in conversation