Prev: Slightly off topic - Is there any point in reporting spam on this group?
Next: correlations when observations are not independant
From: Takeadoe on 12 Jul 2010 09:04 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!
From: Richard A. DeVenezia on 12 Jul 2010 10:05 On Jul 12, 9:04 am, Takeadoe <mtonkov...(a)msn.com> wrote: > 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 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=name name2); set have; array v v1-v4; do over v; * DO OVER is an unsupported construct; if missing (v) then continue; name = vname (v); leave; end; array w v1-v4; do i = 1 to dim(w); if missing (w[i]) then continue; name2 = vname (w[i]); leave; end; run; ------ Other techniques include a transposition.
From: Takeadoe on 12 Jul 2010 10:43 On Jul 12, 10:05 am, "Richard A. DeVenezia" <rdevene...(a)gmail.com> wrote: > On Jul 12, 9:04 am, Takeadoe <mtonkov...(a)msn.com> wrote: > > > > > > > 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 > > 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=name name2); > set have; > array v v1-v4; > do over v; * DO OVER is an unsupported construct; > if missing (v) then continue; > name = vname (v); > leave; > end; > > array w v1-v4; > do i = 1 to dim(w); > if missing (w[i]) then continue; > name2 = vname (w[i]); > leave; > 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
From: Patrick on 12 Jul 2010 16:16 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;
From: Patrick on 12 Jul 2010 16:18
.....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; |