f



set new field to value in first non-null field

Gang - Can someone help with this seemingly simple task.  If we we're
dealing with numeric data, the MAX function would be appropriate, but
I'm working with character data.

Data looks like this:  ("V" stands for variable)

V1 V2 V3 V4
..   .   .   x
x  .   .   .
..  x  .   .

final data set
v3
v1
v2

Ultimately, I want to create 1 variable containg the name of the field
that had the "x" in it.

Mike

Thank you Very Much!
0
Takeadoe
7/12/2010 1:04:17 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

4 Replies
837 Views

Similar Articles

[PageSpeed] 24

On Jul 12, 9:04=A0am, Takeadoe <mtonkov...@msn.com> wrote:
> Gang - Can someone help with this seemingly simple task. =A0If we we're
> dealing with numeric data, the MAX function would be appropriate, but
> I'm working with character data.
>
> Data looks like this: =A0("V" stands for variable)
>
> V1 V2 V3 V4
> . =A0 . =A0 . =A0 x
> x =A0. =A0 . =A0 .
> . =A0x =A0. =A0 .
>
> final data set
> v3
> v1
> v2
>
> Ultimately, I want to create 1 variable containg the name of the field
> that had the "x" in it.
>
> Mike

The VNAME function in conjuction with an iteration over an ARRAY will
perform the search you want.

------
data have;
input (V1-V4) ($);
datalines;
.. . . x
x . . .
.. x . .
run;

data want (keep=3Dname name2);
  set have;
  array v v1-v4;
  do over v;  * DO OVER is an unsupported construct;
    if missing (v) then continue;
    name =3D vname (v);
    leave;
  end;

  array w v1-v4;
  do i =3D 1 to dim(w);
    if missing (w[i]) then continue;
    name2 =3D vname (w[i]);
    leave;
  end;
run;
------

Other techniques include a transposition.
0
rdevenezia (99)
7/12/2010 2:05:03 PM
On Jul 12, 10:05=A0am, "Richard A. DeVenezia" <rdevene...@gmail.com>
wrote:
> On Jul 12, 9:04=A0am, Takeadoe <mtonkov...@msn.com> wrote:
>
>
>
>
>
> > Gang - Can someone help with this seemingly simple task. =A0If we we're
> > dealing with numeric data, the MAX function would be appropriate, but
> > I'm working with character data.
>
> > Data looks like this: =A0("V" stands for variable)
>
> > V1 V2 V3 V4
> > . =A0 . =A0 . =A0 x
> > x =A0. =A0 . =A0 .
> > . =A0x =A0. =A0 .
>
> > final data set
> > v3
> > v1
> > v2
>
> > Ultimately, I want to create 1 variable containg the name of the field
> > that had the "x" in it.
>
> > Mike
>
> The VNAME function in conjuction with an iteration over an ARRAY will
> perform the search you want.
>
> ------
> data have;
> input (V1-V4) ($);
> datalines;
> . . . x
> x . . .
> . x . .
> run;
>
> data want (keep=3Dname name2);
> =A0 set have;
> =A0 array v v1-v4;
> =A0 do over v; =A0* DO OVER is an unsupported construct;
> =A0 =A0 if missing (v) then continue;
> =A0 =A0 name =3D vname (v);
> =A0 =A0 leave;
> =A0 end;
>
> =A0 array w v1-v4;
> =A0 do i =3D 1 to dim(w);
> =A0 =A0 if missing (w[i]) then continue;
> =A0 =A0 name2 =3D vname (w[i]);
> =A0 =A0 leave;
> =A0 end;
> run;
> ------
>
> Other techniques include a transposition.- Hide quoted text -
>
> - Show quoted text -

Thank you Very Much.  I have used the Transpose step before and was
having trouble making it work!

Mike
0
mtonkovich (116)
7/12/2010 2:43:59 PM
That's how it would work with Proc Transpose:

datalines;
.. . . x
x . . .
.. x . .
;
run;

proc transpose data=have out=want(where=(COL1 ne ''));
  by id;
  var v1-v4;
run;

proc print data=want;
run;
0
Patrick
7/12/2010 8:16:57 PM
.....and here with the full code...

data have;
input (V1-V4) ($);
id=_n_;
datalines;
.. . . x
x . . .
.. x . .
;
run;

proc transpose data=have out=want(where=(COL1 ne ''));
  by id;
  var v1-v4;
run;

proc print data=want;
run;
0
Patrick
7/12/2010 8:18:53 PM
Reply: