开发者

How to find out variables with no observations in a large data set?

I have a SAS dataset with more than 1300 variables in it. There are about 200-300 variables that have no observations at all. Is there any way to get a list o开发者_运维百科f these variables that have no observations, so that I can delete those variables from the dataset?


If they are numeric you can do this:

proc means data=sashelp.class n nmiss;
  var _numeric_;  
run;

Cheers Rob


As far as I know, you have to scan through the whole data set.

Something like this should work (warning: untested and may contain typos as I don't have a SAS installation to hand).

%macro drop_unused(libname=,memname=);

proc sql noprint;
  select trim(put(count(1), 8. -L)) into :count_vars from sashelp.vcolumn
    where libname eq "%upcase(&libname)" and memname eq "%upcase(&memname)";
  select trim(left(name)) into :var_1-:var_&count_vars from sashelp.vcolumn
    where libname eq "%upcase(&libname)" and memname eq "%upcase(&memname)";
quit;

data _null_;
  length __missing $ 32767;
  set &libname..&memname end=lastrec;
%do i=1 %to &count_vars;
  retain __missing_&i 'y';
  if not missing(&&var_&i) then __missing_&i = 'n';
%end;
  if lastrec then do;
%do i=1 %to &count_vars;
    if __missing_&i eq 'y' then __missing = trim(left(__missing)) || ' ' || "&&vars_&i";
%end;
    call symput('missing', trim(left(__missing)));
  end;
run;

data new_data;
  set &libname..&memname (drop=&missing);
run;

%mend;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜