home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!seas.smu.edu!convex!darwin.sura.net!paladin.american.edu!auvm!SWIRL.MONSANTO.COM!GIBES
- Message-ID: <9207310250.AA08563@tin.monsanto.com>
- Newsgroups: bit.listserv.sas-l
- Date: Thu, 30 Jul 1992 21:50:32 -0500
- Reply-To: Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
- Subject: RE: DROP variables which are always MISSING?
- Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
- Comments: cc: GIBES@tin.monsanto.com
- Lines: 80
-
- CONTENT: Response
- SUMMARY: Brute-force method to DROP variables which are always MISSING
- REL/PLTF: not applicable
- E-ADDR: gibes@swirl.monsanto.com
- NAME: Kernon Gibes
- PHONE: (708) 506-2873
- DATE: 30 July 1992
-
- Somebody asked:
-
- >Is there any easy way to drop all variables whose values are ALWAYS
- >missing in a SAS data step? There are times when doing a PROC
- >PRINT, for example, that you only want to look at the variables
- >which have values and ignore all the rest, rather than explicitly
- >coding each variable in the VAR statement. Is there any way to
- >conditionally drop variables?
-
- I don't know of an "easy way", but a brute-force method for numeric
- variables is given below. This could obviously be packaged as a macro
- in order to make it "easy" for the user, but it's late and I'm tired...
-
- ___ Source Code ________________________________________________________
-
- options ls=72 nodate;
- data test;
- input a b c d e f;
- cards;
- 1 . 1 . 1 .
- 2 . 2 . . .
- 3 . . . . .
- ;
- run;
-
- proc means data=test noprint;
- output out=miss nmiss=;
- run;
-
- data _null_;
- length varname $ 8 droplist $ 200;
- if 0=1 then set test nobs=n;
- set miss(drop=_type_ _freq_);
- array _nums {*} _numeric_;
- do i=1 to dim( _nums );
- if _nums[i] = n then do;
- call vname( _nums[i], varname );
- droplist = trim( droplist ) || ' ' || varname;
- end;
- end;
- call symput( 'droplist', trim(droplist) );
- stop;
- run;
-
- proc print data=test;
- title1 "Before Dropping Any Variables";
- run;
-
- proc print data=test(drop=&droplist);
- title1 "After Dropping ---ALL MISSING--- Variables";
- title2 "(we dropped: &droplist)";
- run;
-
- ___ Example SAS Output _________________________________________________
-
-
- Before Dropping Any Variables 1
-
- OBS A B C D E F
-
- 1 1 . 1 . 1 .
- 2 2 . 2 . . .
- 3 3 . . . . .
-
- After Dropping ---ALL MISSING--- Variables 2
- (we dropped: B D F)
-
- OBS A C E
-
- 1 1 1 1
- 2 2 2 .
- 3 3 . .
-