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

I want to delete the variables only if all of them (INBNPR,INBINK,INBFRK) are missing using where clause. In this case I want the same output as I got in the previous dataset qisfr15 but I end up with 0 observations. Could you please guide me?

 

 

data qisfr15;
INBNPR=0;
INBINK=2;
INBFRK=.;
run;

proc sql;
create table test as select * from qisfr15
where INBNPR ne . and INBINK ne . and INBFRK ne . ;
quit;

Log:

 

 

27         data qisfr15;
28         INBNPR=0;
29         INBINK=2;
30         INBFRK=.;
31         run;

NOTE: The data set WORK.QISFR15 has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

32         
33         proc sql;
34         create table test as select * from qisfr15
2                                                          The SAS System                          11:55 Tuesday, September 18, 2018

35         where INBNPR ne . and INBINK ne . and INBFRK ne . ;
NOTE: Table WORK.TEST created, with 0 rows and 3 columns.

36         quit;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
proc sql;
create table test as select * from qisfr15
where nmiss(INBNPR,INBINK,INBFRK)<3;
quit;
Thanks,
Jag

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

Your query is keep the observations where it is true that ALL three variables are NOT missing, so if any of the three IS missing then exclude that observation.

 

You want to keep the observations where it is NOT true that ALL three variables are missing.

where not (INBNPR=. and INBINK=. and INBFRK=.)

Our you can use De Morgan's law and convert to an expression using OR instead.  So look for observations where at least one of them is not missing.

where INBNPR ne . or INBINK ne . or INBFRK ne .

 

 

Jagadishkatam
Amethyst | Level 16
proc sql;
create table test as select * from qisfr15
where nmiss(INBNPR,INBINK,INBFRK)<3;
quit;
Thanks,
Jag
PaigeMiller
Diamond | Level 26

Although you have asked to delete VARIABLES, your code and the code of the other people are deleting OBSERVATIONS.

 

Do you want to delete VARIABLES? Or do you want to delete OBSERVATIONS?

--
Paige Miller
Babloo
Rhodochrosite | Level 12
I want to delete the observations if all the variables mentioned in the
initial post are missing.
Reeza
Super User
Then your code is correct.
ChrisNZ
Tourmaline | Level 20

In that case, @Jagadishkatam's answer is the most elegant in my opinion.

Also please change the post title to reflect your actual question (delete observations).

Reeza
Super User
If you want to check if all values of a variable are missing PROC FREQ with the NLEVELS data set is the best method. You cannot drop variables within a WHERE statement, you can only drop observations.

SAS Innovate 2025: 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. Sign up by March 14 for just $795.


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
  • 7 replies
  • 1799 views
  • 6 likes
  • 6 in conversation