BookmarkSubscribeRSS Feed
ysmnkmlia
Calcite | Level 5

Hi, i have a dataset of pisa2022 and i need to filter out observation with missing value at any variable. The solution is preferably to be in the data step. Is there anyone with an idea to solve this?

 

Below is my data step before removing the observation with missing value

 

data work.Project_pisa2022;
set pisa2022.Project_pisa2022;
keep CNT ST004D01T PV1MATH PV2MATH PV3MATH PV4MATH PV5MATH PV6MATH PV7MATH PV8MATH PV9MATH PV10MATH
PV1READ PV2READ PV3READ PV4READ PV5READ PV6READ PV7READ PV8READ PV9READ PV10READ
PV1SCIE PV2SCIE PV3SCIE PV4SCIE PV5SCIE PV6SCIE PV7SCIE PV8SCIE PV9SCIE PV10SCIE;
where CNT in('MYS', 'SGP', 'CHE');

run;

2 REPLIES 2
Patrick
Opal | Level 21

Something along the line of below should work for you.

data work.have;
  set sashelp.class;
  if _n_=5 then call missing(name,age);
  if _n_=8 then call missing(height);
run;

proc sql noprint;
  select name into :varlist separated by ','
  from dictionary.columns
  where libname='WORK' and memname='HAVE'
  ;
quit;

data work.want;
  set have;
  if cmiss(&varlist)>0 then delete;
run;

proc print data=work.want;
run;
FreelanceReinh
Jade | Level 19

Hi @ysmnkmlia and welcome to the SAS Support Communities!

 

Similar to Patrick's solution, you can also replace the KEEP statement with a KEEP= dataset option and then apply the CMISS function to the _ALL_ variable list:

data work.Project_pisa2022;
set pisa2022.Project_pisa2022(keep=CNT ST004D01T
  PV1MATH PV2MATH PV3MATH PV4MATH PV5MATH PV6MATH PV7MATH PV8MATH PV9MATH PV10MATH
  PV1READ PV2READ PV3READ PV4READ PV5READ PV6READ PV7READ PV8READ PV9READ PV10READ
  PV1SCIE PV2SCIE PV3SCIE PV4SCIE PV5SCIE PV6SCIE PV7SCIE PV8SCIE PV9SCIE PV10SCIE);
where CNT in('MYS', 'SGP', 'CHE');
if cmiss(of _all_)=0;
run;

sas-innovate-wordmark-2025-midnight.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. 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
  • 2 replies
  • 774 views
  • 4 likes
  • 3 in conversation