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.
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.