BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mayasak
Quartz | Level 8

Hi,

I need to delete observations that have ns_n ='.' or 0 but leave the rows that have a certain value of drug= 'abc' (which intrinsically has ns_n equal to '.' and 0; they have other values - uns_n and sns_n instead). 

When I use this code below all rows containing ns_n ='.' or 0 are deleted including the data with drug 'abc' and I need to keep them:

Data DB_test;
set AB_2020;
if ns_n='.' then delete;
if ns_n =0 then delete;
run;

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First of all, one of your statements is wrong and works only because SAS does an automatic type conversion for you. Relying on this is considered bad practice.

Assuming your variable is numeric, do this:

if drug ne 'abc' and ns_n in (0,.) then delete;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

First of all, one of your statements is wrong and works only because SAS does an automatic type conversion for you. Relying on this is considered bad practice.

Assuming your variable is numeric, do this:

if drug ne 'abc' and ns_n in (0,.) then delete;
Astounding
PROC Star
Similar to your earlier question, you can use:

if drug='abc' or ns_n;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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