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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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