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 (November 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 26 Nov 2008 13:24:21 -0800
Reply-To:     Adriano Rodrigues <adriano@GPP.COM.BR>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Adriano Rodrigues <adriano@GPP.COM.BR>
Subject:      RES: tranpose learn
Comments: To: Jim Groeneveld <jim.1stat@YAHOO.COM>
In-Reply-To:  <200811261515.mAQBlZaV017531@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

Thanks Jim, i will check it out!

Adriano

-----Mensagem original----- De: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] Em nome de Jim Groeneveld Enviada em: quarta-feira, 26 de novembro de 2008 07:15 Para: SAS-L@LISTSERV.UGA.EDU Assunto: Re: tranpose learn

Hi Adriano,

This, hinging more than one variable at a time, is not easily possible with PROC TRANSPOSE. It may involve multiple PROC TRANSPOSE steps and data steps, merging datasets.

That is why I wrote my macro MR2RM, see http://tinyurl.com/2okul8 for download instructions. With it you can run the following code:

DATA TestData; LENGTH Name status phone1 phone2 why1 why2 hour1 hour2 date1 date2 $9; INPUT Name status phone1 phone2 why1 why2 hour1 hour2 date1 date2; DATALINES; Josh no_answer 555123 555124 411 411 19:10 19:12 22/11 22/11 Josh no_answer 555123 555124 411 444 08:05 08:07 23/11 23/11 ; RUN; /* 'no answer' changed to 'no_answer'; else unable to read directly*/

TITLE "TestData"; PROC PRINT DATA=TestData; RUN;

* General macro MR2RM solution; %MR2RM (Data=TestData, Out=Flattened, Overwrit=Y, ByList=Name status phone1 phone2, VarList=why1 why2 hour1 hour2 date1 date2);

TITLE "Flattened"; PROC PRINT DATA=Flattened; RUN;

The resulting variable names are more logical than the ones that you provided in your example. If desired you may rename them (PROC DATASETS).

Instead you can also use a dedicated data step:

* Dedicated data step solution; DATA Hinged (DROP = why1 why2 hour1 hour2 date1 date2); SET TestData; BY Name status phone1 phone2; RETAIN Why11 Why21 Hour11 Hour21 Date11 Date21 Why12 Why22 Hour12 Hour22 Date12 Date22; IF (FIRST.Phone2) THEN DO; Why11 = Why1; Why21 = Why2; Hour11 = Hour1; Hour21 = Hour2; Date11 = Date1; Date21 = Date2; END; ELSE IF (LAST.Phone2) THEN DO; Why12 = Why1; Why22 = Why2; Hour12 = Hour1; Hour22 = Hour2; Date12 = Date1; Date22 = Date2; OUTPUT; END; RUN;

TITLE "Hinged"; PROC PRINT DATA=Hinged; RUN;

or a dedicated data step solution involving arrays.

Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld

On Wed, 26 Nov 2008 10:16:24 -0800, Adriano Rodrigues <adriano@GPP.COM.BR> wrote:

>Hi all, > > > >Trying to make one transpose on my data, but this not work well. > > > >The daily data is: > >Name status phone1 phone2 why1 why2 hour1 hour2 date1 date2 > >Josh no answer 555123 555124 411 411 19:10 19:12 22/11 22/11 > > >Josh no answer 555123 555124 411 444 08:05 08:07 23/11 23/11 > > >. > >New shape I want: > >Name status phone1 phone2 why1 why2 hour1 hour2 date1 date2 >why11 why21 hour11 hour12 date11 date12 > >Josh no answer 555123 555124 411 411 19:10 19:12 22/11 >22/11 411 444 08:05 08:07 23/11 23/11 > >. > > > > > >Thanks, > >Adriano


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