LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 20 Dec 2007 09:04:48 -0500
Reply-To:     Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:      Re: How to extract unary variables from a dataset automately?
Comments: To: Hu Yang <sheepsas@gmail.com>
In-Reply-To:  <cefe1b0712191515y1e373dcch1f6383943999f011@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

I assume that by "unary" you mean all variables that have the same value for each record.

For numeric variables, I would use PROC SUMMARY -- get and transpose an output data set, then check to see whether the MIN and MAX are the same (with an extra check or two if you have missing values to contend with).

Mike Rhoads Westat RhoadsM1@Westat.com

data newclass; set sashelp.class; AllMissing = .; UnaryVar = 111; UnaryVarPartMissing = UnaryVar; AgePartMissing = Age; if _N_ = 1 then do; UnaryVarPartMissing = .; AgePartMissing = .; end; run;

proc summary data=newclass; var _numeric_; output out=summout (drop=_TYPE_); run;

proc transpose data=summout (drop=_FREQ_) out=transout; id _STAT_; var _NUMERIC_; run;

proc sql noprint; select _NAME_ into :UnaryVarList separated by ' ' from transout, summout (keep=_FREQ_ _STAT_ where=(_STAT_='N')) where min = max and /* Either all missing values or no missing values */ (n = 0 OR n = _FREQ_) ; quit;

%PUT Unary variables: &UnaryVarList;

-----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Hu Yang Sent: Wednesday, December 19, 2007 6:16 PM To: SAS-L@listserv.uga.edu Subject: How to extract unary variables from a dataset automately?

hi there,

I want to get rid of the unary variables in a very large dataset.

One idea is to use proc freq. But if the dataset is large and contains too many variables such as 3000, the method would be very slow. Is there an efficient way (both in time and space) to automately extract the unary variables' name into a macro variable?

Thanks a lot!

Hu


Back to: Top of message | Previous page | Main SAS-L page