home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / bit / listserv / sasl / 3507 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.9 KB  |  94 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!seas.smu.edu!convex!darwin.sura.net!paladin.american.edu!auvm!SWIRL.MONSANTO.COM!GIBES
  3. Message-ID: <9207310250.AA08563@tin.monsanto.com>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Thu, 30 Jul 1992 21:50:32 -0500
  6. Reply-To:     Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Kernon Gibes <gibes@SWIRL.MONSANTO.COM>
  9. Subject:      RE: DROP variables which are always MISSING?
  10. Comments: To: SAS-L@uga.cc.uga.edu@tin.monsanto.com
  11. Comments: cc: GIBES@tin.monsanto.com
  12. Lines: 80
  13.  
  14.  CONTENT:   Response
  15.  SUMMARY:   Brute-force method to DROP variables which are always MISSING
  16.  REL/PLTF:  not applicable
  17.  E-ADDR:    gibes@swirl.monsanto.com
  18.  NAME:      Kernon Gibes
  19.  PHONE:     (708) 506-2873
  20.  DATE:      30 July 1992
  21.  
  22. Somebody asked:
  23.  
  24. >Is there any easy way to drop all variables whose values are ALWAYS
  25. >missing in a SAS data step?  There are times when doing a PROC
  26. >PRINT, for example, that you only want to look at the variables
  27. >which have values and ignore all the rest, rather than explicitly
  28. >coding each variable in the VAR statement.  Is there any way to
  29. >conditionally drop variables?
  30.  
  31. I don't know of an "easy way", but a brute-force method for numeric
  32. variables is given below.  This could obviously be packaged as a macro
  33. in order to make it "easy" for the user, but it's late and I'm tired...
  34.  
  35. ___ Source Code ________________________________________________________
  36.  
  37. options ls=72 nodate;
  38. data test;
  39.   input a b c d e f;
  40. cards;
  41. 1  .  1  .  1  .
  42. 2  .  2  .  .  .
  43. 3  .  .  .  .  .
  44. ;
  45. run;
  46.  
  47. proc means data=test noprint;
  48. output out=miss nmiss=;
  49. run;
  50.  
  51. data _null_;
  52.    length varname $ 8 droplist $ 200;
  53.    if 0=1 then set test nobs=n;
  54.    set miss(drop=_type_ _freq_);
  55.    array _nums {*} _numeric_;
  56.    do i=1 to dim( _nums );
  57.       if _nums[i] = n then do;
  58.           call vname( _nums[i], varname );
  59.           droplist = trim( droplist ) || ' ' || varname;
  60.         end;
  61.    end;
  62.    call symput( 'droplist', trim(droplist) );
  63.  stop;
  64. run;
  65.  
  66. proc print data=test;
  67. title1 "Before Dropping Any Variables";
  68. run;
  69.  
  70. proc print data=test(drop=&droplist);
  71. title1 "After Dropping ---ALL MISSING--- Variables";
  72. title2 "(we dropped: &droplist)";
  73. run;
  74.  
  75. ___ Example SAS Output _________________________________________________
  76.  
  77.  
  78.                      Before Dropping Any Variables                     1
  79.  
  80.                    OBS    A    B    C    D    E    F
  81.  
  82.                     1     1    .    1    .    1    .
  83.                     2     2    .    2    .    .    .
  84.                     3     3    .    .    .    .    .
  85.  
  86.                After Dropping ---ALL MISSING--- Variables              2
  87.                          (we dropped:   B D F)
  88.  
  89.                            OBS    A    C    E
  90.  
  91.                             1     1    1    1
  92.                             2     2    2    .
  93.                             3     3    .    .
  94.