LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 1 Feb 2000 17:49:18 +0100
Reply-To:     detecsm_hellriegelg@WESTLB.DE
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Gehard Hellriegel <detecsm_hellriegelg@WESTLB.DE>
Subject:      Re: delete many variables - Macro
Content-type: text/plain; charset=us-ascii

... an idea, how the macro could look like: AND: a litte correction: do NOT use SUM= as statistic!! The sum of -1 and 1 is also 0!!!!! Also other statistics might be not ok! So that code might be ok:

/* some testdata */ data abc; a1=1; a2=0; b=2; c=0; output; a1=1; a2=0; b=-2; c=0; output; a1=2; a2=0; b=2; c=0; output; a1=3; a2=0; b=-2; c=0; output; a1=1; a2=0; b=2; c=0; output; a1=-11; a2=1; b=-2; c=0; output; run;

/* the macro */ %macro drop(data=,varlist=); data test; set &data end=eof; array v(*) &varlist; /* list all your numeric variables c1-c?? */ do i=1 to dim(v); v(i)=sum(abs(v(i)),lag(v(i))); end; drop i; if eof then output; run; /* use TRANSPOSE to get the variables in _NAME_ and the SUMs in COL1: */ proc transpose data=test out=test; run; data _null_; set test; retain counter 0; if col1=0 then do; counter=counter+1; call symput("no",counter); call symput("n"!!compress(put(counter,5.)),_name_); end; run;

/* then build the DROP list with a macro loop: */ data &data; set &data; drop %do i=1 %to &no; &&n&i %end; ; run; %mend; options mprint; %drop(data=abc, varlist=a1 a2 b c);

Hui Huang <huihuang@IUPUI.EDU> on 01.02.2000 16:21:46

Bitte antworten an Hui Huang <huihuang@IUPUI.EDU>

An: SAS-L@LISTSERV.UGA.EDU Kopie: (Blindkopie: DeTeCSM HellriegelG/D/ExternalStaff/WLB) Thema: delete many variables

Hi all,

Is there any way to delete many variables from a dataset? For exampl dataset AAA looks like this:

c1 c2 c2 c4 1 0 1 0 0 0 1 0 1 0 1 0

I want to delete variable c2 and c4 because every obs' value is 0 for those variables. My point is how to delete some variables with all values of obs in those variables 0's, but you don't know exactly which variables have this property in advance, and therefore need to use some sentences to do the judgement work?

Any responses will be appreciated.

Hui

Mit freundlichen Gruessen

DeTeCSM, Gerhard Hellriegel

WestLB Abteilung: 001-80622 Aderstr. 22 D - 40217 Duesseldorf Tel.: +49211 826 6173 Fax: +49211 826 5393


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