D******n 发帖数: 2836 | 1 any easy proc to get the number of missing values of all the character
variables in a data set? |
f*******e 发帖数: 51 | 2 data _null_;
set yourfile end=eof;
array char _character_ ;
do over char;
if char =" " then inx+1;
end;
if eof then call symput("total", left(inx));
%put &total;
run;
not sure if it's what u need or not |
D******n 发帖数: 2836 | 3 what i want is the number of missing values for each var not a lump sum
【在 f*******e 的大作中提到】 : data _null_; : set yourfile end=eof; : array char _character_ ; : do over char; : if char =" " then inx+1; : end; : if eof then call symput("total", left(inx)); : %put &total; : run; : not sure if it's what u need or not
|
l*********s 发帖数: 5409 | 4 proc format;
value $miss " "="missing"
other="nomissing";
run;
proc freq data=temp;
tables charvar / missing;
format charvar $miss.;
run; |
d*******o 发帖数: 493 | 5 这个码牛,可见多年功力,赞一个
【在 f*******e 的大作中提到】 : data _null_; : set yourfile end=eof; : array char _character_ ; : do over char; : if char =" " then inx+1; : end; : if eof then call symput("total", left(inx)); : %put &total; : run; : not sure if it's what u need or not
|
d*******o 发帖数: 493 | 6 proc sql;
select count(*)-count(var1) as num_missing1, count(*)-count(var2)as num_
missing2
from yourtable
;quit; |
D******n 发帖数: 2836 | 7 if i have many , i have type them all? I am using the modified version of
littlebirds' solution
proc format;
value $miss " "="missing"
other="nomissing";
run;
proc freq data=temp;
tables _character_ / missing;
format _character_ $miss.;
run;
this is pretty close to what i want but it would be better if the tables are
aggregated into one. |
s*r 发帖数: 2757 | |
f*******e 发帖数: 51 | 9 想不出简单的。。。
proc sql noprint;
select name into : varlst separated by " "
from sashelp.vcolumn
where libname="yourlib" and memname="yourfile" and type="char";
quit;
%put &varlst;
proc transpose data=yourfile out=yourfile2;
var &varlst;
run;
data yourfile2;
set yourfile2;
array char _character_ ;
count=0;
do over char; if char =" " then count+1;
end;
keep _name_ count;
run;
【在 D******n 的大作中提到】 : any easy proc to get the number of missing values of all the character : variables in a data set?
|
s******y 发帖数: 352 | 10 Code works only on SAS9.2.
data class;
set sashelp.class;
array temp $10. name sex cheight cweight cage;
cheight=cats(height);
cweight=cats(height);
cage=cats(age);
do over temp;
if ranuni(123456)<0.3 then call missing(temp);
end;
keep name sex c:;
run;
proc print;
run;
proc format;
value $miss " "="missing"
other="nomissing";
run;
proc tabulate data=class missing out=out;
class _character_;
table _all_,N;
format _character_ $miss.;
run;
data want(keep=var N rename=(N=miss));
set out;
array all |
|
|
D******n 发帖数: 2836 | 11 it doesnt work in my system. |
o****o 发帖数: 8077 | 12 data _null_;
if _n_=1 then do;
length name $ 32;
declare hash h();
h.defineKey('name');
h.defineData('name', 'nmiss');
h.defineDone();
end;
set yourtable end=eof;
array _c{*} _character_;
if _n_=1 then do
j=1 to dim(_c); _x=vname(_c[j]); put _x=;
if dim(_c)=1 then stop;
end;
do j=2 to dim(_c);
if missing(_c[j]) then do;
if h.find(key:vname(_c[ |
D******n 发帖数: 2836 | 13 corrected some typos and it worked. |
b******e 发帖数: 539 | 14 proc summary data=xxxx;
var _character_;
output out=test nmiss=;
run; |
D******n 发帖数: 2836 | 15 This just simply doesn't work. nmiss is for numerics i guess. |
b******e 发帖数: 539 | 16 that's right -- i only used on numeric values and thought it would be the
same for character values :(
【在 D******n 的大作中提到】 : This just simply doesn't work. nmiss is for numerics i guess.
|
b******e 发帖数: 539 | 17 then you can use a data step -- you need to know how many character
variables you have and their sequence in advance, which should be easy.
then:
assume you have 100 char variables:
data one (keep=count1-count100);
set xxx end=last;
retain count1-count100;
array char(*) _character_;
array count(100);
do i = 1 to dim(char);
count(i) = count(i) + missing(char(i));
end;
if last then output;
run; |