LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 13 Dec 2004 12:54:23 -0600
Reply-To:   PuddingDotMan@GmailDotCom.UGA.EDU
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Pudding Man <pudding.man@GMAIL.COM>
Subject:   Re: reshaping data
Comments:   To: Hayrettin Okut <hokut1@yahoo.com>
In-Reply-To:   <20041212105838.136.qmail@web53905.mail.yahoo.com>
Content-Type:   text/plain; charset=US-ASCII

Hayrettin claims 14 periods but offers only 13 lines of data. Var DEN varies across the 13 records. The INPUT statement below has 4 + 7 = 11 vars, the data appears to have 12 values.

This is a messy query ...

The input data structure is not much designed for the desired result ...

Doesn't mean it can't be done. Just suggests that that it might be, well, messy.

Suppose that there were 13 input records corresponding to 13 periods and that neither DEN nor the 12th data value were a concern, and that the desired SAS dataset structure is implied by the second INPUT statement in Hayrettin's query, -and- that such structure will actually facilitate Hayrettin's work ...

Perhaps we could write a macro to declare 13 implicit arrays for the 13 input recs and another implicit "array of arrays" to facilitate reading the data in, checking NO AGE BT for consistency as we go. Following (tested) illustrative code might suggest an approach:

options mprint; %macro dumb;

%do i = 1 %to 13; array xx&i(_i_) a&i b&i c&i d&i e&i f&i g&i; %end;

array xxall(_j_) %do j = 1 %to 13; xx&j %end; ;

%mend dumb;

data b(drop = _:); %dumb; input no age bt +3 xx1(*) @1 _ck $12. ;

do _j_ = 2 to 13; input @1 _ckx $12. +3 @; if _ck = _ckx then do _i_ = 1 to 7; input xxall @; end; else put / 'data inconsistency:' _ck= _ckx= / _all_ /; input; end;

put // _all_; cards; 21331132 3 1 1 192 35.65 0 . 0 . 280 5 21331132 3 1 2 206 37.77 0 . 0 . 370 5 21331132 3 1 3 220 39.90 0 2 0 4 120 13 21331132 3 1 4 234 41.22 0 5 0 2 124 11 21331132 3 1 5 248 42.41 2 5 0 1 210 9 21331132 3 1 6 262 43.67 2 5 0 5 247 13 21331132 3 1 7 276 44.95 2 8 0 3 196 11 21331132 3 1 8 290 47.37 0 6 1 2 82 20 21331132 3 1 9 304 50.63 1 2 0 0 255 8 21331132 3 1 10 318 53.40 0 3 0 0 130 5 21331132 3 1 11 332 55.50 1 5 0 1 285 2 21331132 3 1 12 346 57.47 2 4 0 2 . 0 21331132 3 1 13 360 59.10 0 1 0 0 454 1 ; run;

Well, it could've been messier. Hope it hep's ...

Skoal, Puddin'

****************************************************** *** Puddin' Man PuddingDotMan at GmailDotCom *** ******************************************************;

"I was lying in a burned out basement With the full moon in my eyes. I was hoping for replacement When the sun burst thru the sky." - from "After The Gold Rush", Neil Young

On Sun, 12 Dec 2004 02:58:38 -0800, Hayrettin Okut <hokut1@yahoo.com> wrote: > Dear all; > > I have a longitudinal data from 14 periods on 32 individuals. The data file is > listed blow. The variables for each period have been edited in sequence. I need to reshape my data as put each variable of from each period to in a different > column; That is currently data set is; > > data a; > > input no age bt den a b c d e f g; > > cards; > > This data set need be be reformed as ; > > data b; > input no age bt den a1-a14 b1-b14 c1-c14 d1-d14 e1-e14 f1-f14 g1-g14; > cards; > I would be greatly appreciated to get your helps. > > Best wishes, > > Hokut > > data a; > > input no age bt den a b c d e f g; > > cards; > > 21431132 3 1 1 192 35.65 0 . 0 . 280 5 > > 21431132 3 1 2 206 37.77 0 . 0 . 370 5 > > 21431132 3 1 3 220 39.90 0 2 0 4 120 13 > > 21431132 3 1 4 234 41.22 0 5 0 2 124 11 > > 21431132 3 1 5 248 42.41 2 5 0 1 210 9 > > 21431132 3 1 6 262 43.67 2 5 0 5 247 14 > > 21431132 3 1 7 276 44.95 2 8 0 3 196 11 > > 21431132 3 1 8 290 47.37 0 6 1 2 82 20 > > 21431132 3 1 9 304 50.63 1 2 0 0 255 8 > > 21431132 3 1 10 318 53.40 0 3 0 0 140 5 > > 21431132 3 1 11 332 55.50 1 5 0 1 285 2 > > 21431132 3 1 12 346 57.47 2 4 0 2 . 0 > > 21431132 3 1 13 360 59.10 0 1 0 0 454 1


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