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;
proc sql;
create table test as select * from qisfr15
where nmiss(INBNPR,INBINK,INBFRK)<3;
quit;
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 .
proc sql;
create table test as select * from qisfr15
where nmiss(INBNPR,INBINK,INBFRK)<3;
quit;
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?
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).
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.
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.
Ready to level-up your skills? Choose your own adventure.