shabani
06-01-2009, 05:08 PM
I'm trying to remove blanks across X columns for each observation. So my data looks like this:
var1 var2 var3 ... varX
x1 x3
y2 y3
z2
and I want to turn it into this:
var1 var2 var3 ... varX
x1 x3
y2 y3
z2
One potential problems is that I'm going to do this for a large number of datasets and X differs for each dataset, so I want an automated way to do this.
This is what I've written so far, where &X is a global macro variable defined in a previous step:
data temp03;
array line[&X] $ 60 ;
set temp02;
array nlines {*} line1-line&X;
do i = 1 to (&X);
if nlines(i) = "" and nmiss(of nlines(i+1)-line&X) ne (&X-i) then do;
array nlines2 {*} nlines(i)-line&X;
do j = 1 to (&X-i);
nlines2(j) = nlines2(j+1);
call missing(nlines2(j+1));
end;
end;
end;
run;
I think the issue I'm having results from the term "nlines(i+1)". For example, when i = 1, instead of writing "line2" it writes the actual value of the variable line2. Is there an easy way to refer to the NAME of an array element rather than the value?
Also, I'm sure there are many other ways to remove the blanks, so if you know of any please let me know.
Any help is very much appreciated!!! Thanks!!!
var1 var2 var3 ... varX
x1 x3
y2 y3
z2
and I want to turn it into this:
var1 var2 var3 ... varX
x1 x3
y2 y3
z2
One potential problems is that I'm going to do this for a large number of datasets and X differs for each dataset, so I want an automated way to do this.
This is what I've written so far, where &X is a global macro variable defined in a previous step:
data temp03;
array line[&X] $ 60 ;
set temp02;
array nlines {*} line1-line&X;
do i = 1 to (&X);
if nlines(i) = "" and nmiss(of nlines(i+1)-line&X) ne (&X-i) then do;
array nlines2 {*} nlines(i)-line&X;
do j = 1 to (&X-i);
nlines2(j) = nlines2(j+1);
call missing(nlines2(j+1));
end;
end;
end;
run;
I think the issue I'm having results from the term "nlines(i+1)". For example, when i = 1, instead of writing "line2" it writes the actual value of the variable line2. Is there an easy way to refer to the NAME of an array element rather than the value?
Also, I'm sure there are many other ways to remove the blanks, so if you know of any please let me know.
Any help is very much appreciated!!! Thanks!!!