```Date: Tue, 23 Jan 2007 12:56:41 -0500 Reply-To: "data _null_;" Sender: "SAS(r) Discussion" From: "data _null_;" Subject: Re: Data structure conversion problem Comments: To: "Kevin F. Spratt" In-Reply-To: <7.0.1.0.2.20070123081616.05770fd8@Dartmouth.Edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I know this has been answered adequately but it's too cold(for me) to go fishin'. data work.one; infile cards eof=eof; input x y / z:\$30. p:\$50.; array _z[10] z1-z10; /* init array to zero */ call poke(repeat(put(0,rb8.),dim(_z)-1),addr(z1),8*dim(_z)); do _n_ = 1 by 1; index = input(scan(z,_n_,'|'),f2.); if missing(index) then leave; _z[index]=1; end; array _p[10]\$10 p1-p10; length w \$10; retain totalNumberOfPs 0; do _n_ = 1 by 1; w = scan(p,_n_,'|'); if missing(w) then leave; totalNumberOfPs = max(totalNumberOfPs,_n_); _p[_n_] = w; end; return; eof: putlog totalNumberOfPs=; call symputx('dropThesePs',cats('P',totalNumberOfPs+1,'-P',dim(_p)),'F'); call execute('%put NOTE: dropThesePs=&dropThesePs;'); stop; drop p z index w totalNumberOfPs; cards; 1 2 2|3|5 12.34|234.8|1280.0 2 4 2|4|5 12.34|123.0|2345.2 3 2 2|5|7 133.1 4 1 1|7|8|10 154.3|2345.99|v27.4 ;;;; run; proc print data=_last_(drop=&dropThesePs); run; On 1/23/07, Kevin F. Spratt wrote: > Suppose the following data structure has been imposed upon you. > > DATA > WORK.ONE; > > > input x y > \$z \$p; > > cards; > > 1 2 > 2|3|5 12.34|234.8|1280.0 > > 2 4 > 2|4|5 12.34|123.0|2345.2 > > 3 2 > 2|5|7 133.1 > > 4 1 > 1|7|8|10 154.3|2345.99|v27.4 > > ; > > > variables x and y are numeric and variable z and p are character but > actually represent > a series of values the are delimited by a |. > > 1. For variable Z you know than then number of possible values is > 10 , and you would like > to create 10 separate variables coded as 0 of 1 depending on > the value of the score. > > 2. for variable p you don't know how many possible values there > are, but do know that > some of these values may be numeric and others character. For > this variable, you simply > want to create a separate variable p1-p? for each variable. > > Thus, if the data is as shown above, you would like the restructured data > to look like what I have typed below. (if the numbers don't match, this > is simply my typo)? > > Okay programming gurus, how do you do > it? > > > > > x y z1 z2 z3 z4 z5 z6 z7 z8 z9 > z10 p1 p2 p3 > > 1 2 0 1 1 0 1 0 0 0 0 0 12.34 234.8 1280.0 > > 2 4 0 1 0 1 1 0 0 0 0 0 13.34 123.0 2345.2 > > 3 2 0 1 0 0 1 0 1 0 0 0 133.1 > > 4 1 1 0 0 0 0 0 1 1 0 1 154.3 2345.99 V27.4 > > > ______________________________________________________________________ > > Kevin F. Spratt, Ph.D. > Department of Orthopaedic Surgery > Dartmouth Medical School > One Medical Center Drive > DHMC > Lebanon, NH USA 03756 > (603) 653-6012 (voice) > (603) 653-6013 (fax) > (603) 252-5922 (cell) > Kevin.F.Spratt@Dartmouth.Edu (e-mail) > _______________________________________________________________________ > ```

Back to: Top of message | Previous page | Main SAS-L page