UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Code Fragments
Eliminate Useless Variables

The example below shows how to eliminate variables that has only missing values. This code is adapted from SAS-L archives – July 2001, week 5

data temp;
input x y z;
cards;
1 . 2
2 . 3
4 . 6
;
run;
/***replace 'temp' below with the name of your data set****/
%let have = temp;
/**Do not change anything below**/
*discover min and max for all numeric vars. ;
proc means data=&have noprint ;  
  output out=_temp_1; 
  run;
*organize as one observation for each numeric var. ;
proc transpose data=_temp_1 out=_temp_2 name = _stat_ ; 
  id _stat_; 
run;
/**Create the list of variables to be dropped***/
proc sql noprint;  
   select _stat_ into :dropList separated by ' '
   from _temp_2
   where min = max and max = . ;
quit;
/*Replace 'temp1' with the name of your (new) dataset*/
data temp1 ( drop=&dropList ); 
  set &have;
run;
proc print data=temp1;
run;
   
Obs    x    z
 1     1    2
 2     2    3
 3     4    6 

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California