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

I have a dataset of 1000 plus variables - all numeric. Not all of them are useful. I wanted to drop the variables where the mean if less than a threshold value. I thought of two approaches but couldn't execute either as I am a complete beginner in SAS.

Approach 1: Use proc means to calculate mean of all variables in input dataset x and output it to another dataset y. Then write a step which checks dataset y where mean = 0 and matches the name with dataset x. if match = positive then delete.

Approach 2: Is there a way to write if mean of var = 0, then delete var.

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

This is a variant on a frequently asked question - how to drop variables that all have missing values.

Change the code slightly here in the first step will get you what you want. Replace the _nobs_ with _mean_

*generate sample data;

data class;

set sashelp.class;

new_var=0;

run;

proc univariate data=class outtable=ot(keep=_var_ _mean_) noprint;

var _numeric_;

run;

proc sql noprint;

select _var_ into :vList separated by " "

from ot where _mean_=0;

quit;

data clean;

set class;

drop &vList;

run;


View solution in original post

1 REPLY 1
Reeza
Super User

This is a variant on a frequently asked question - how to drop variables that all have missing values.

Change the code slightly here in the first step will get you what you want. Replace the _nobs_ with _mean_

*generate sample data;

data class;

set sashelp.class;

new_var=0;

run;

proc univariate data=class outtable=ot(keep=_var_ _mean_) noprint;

var _numeric_;

run;

proc sql noprint;

select _var_ into :vList separated by " "

from ot where _mean_=0;

quit;

data clean;

set class;

drop &vList;

run;


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1366 views
  • 1 like
  • 2 in conversation