data test;
input x y z;
datalines;
. . 1
. . .
2 2 2
. 3 .
4 4 .
;
run;
data test1;
set test;
n+1;
x1=lag(x);
if (n=2 and x=. and x1=.) then x2="dele";
y1=lag(y);
if (n=2 and y=. and y1=.) then y2="dele";
z1=lag(z);
if (n=2 and z=. and z1=.) then z2="dele";
if n=2;
keep x2 y2 z2;
run;
There should be easy ways, but this is the best I can come up with.
/* Assume we start with data set Original and end up with Final */ /* Generate data set containing only the first two observations */ proc sql inobs=2; create table test as select * from original; quit;
/* Use Proc Means to output the missing value of each variable */ proc means data=test noprint; output out=test2 nmiss=/autoname; run;
/* Transpose the form of the data set to the form we can handle */ proc transpose data=test2(drop=_TYPE_ _FREQ_) out=test3(drop=Label) NAME=Source LABEL=Label PREFIX=MIS; run; /* Get rid of the '_NMiss' at the end of the variable name to recover the original variable name */ data test4; set test3; Name=trim(tranwrd(source,'_NMiss','')); run;
/* Put the variable names in a macro, which have one or none missing value*/ proc sql noprint; select Name into:keep separated by ' ' from test4 where mis1<2; quit;
/* If interested, you can look at the log to see which ones were kept */ %put &keep; /* Clean up the room */ proc datasets nolist; delete test test1 test2 test3 test4; run; /* Keep only the good ones :-)*/ data final; set original(keep=&keep); run;