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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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