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;


sas-innovate-2024.png

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.

 

Register now!

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.

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