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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.