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 (April 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 3 Apr 2003 08:22:38 -0500
Reply-To:     diskin.dennis@KENDLE.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         diskin.dennis@KENDLE.COM
Subject:      Re: Q: Can this be done with proc transpose?
Comments: To: "Becker, Eckhard [IAW-06]" <EBecker@VHV.DE>
Content-type: text/plain; charset=us-ascii

Eckhard,

One way of many ways to do it:

data test; name='A'; klasse=1; werta=1; wertb=2; output; name='A'; klasse=2; werta=11; wertb=22; output; name='B'; klasse=1; werta=111; wertb=221; output; run;

data t(drop=werta wertb klasse); set test; kl='a' || put(klasse,1.); wert=werta; output; kl='b' || put(klasse,1.); wert=wertb; output; run;

/* assuming your data is sorted by name */ proc transpose data=t out=tt(drop=_name_) prefix=wert; by name; id kl; var wert; run

HTH, Dennis Diskin

From: "Becker, Eckhard [IAW-06]" <EBecker@VHV.DE>@LISTSERV.UGA.EDU> on 04/03/2003 07:09 AM

Please respond to "Becker, Eckhard [IAW-06]" <EBecker@VHV.DE>

Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>

To: SAS-L@LISTSERV.UGA.EDU cc:

Subject: Q: Can this be done with proc transpose?

Hi everyone,

I have a dataset with variables (sorted by name and klasse

name klasse werta wertb...

and want to transpose it to

name werta(klasse=1) wertb(klasse=1) ... werta(klasse=2) wertb(klasse=2) ...

klasse can have values from 1 to 9. I tried to do this with proc transpose but couldnt find a solution. I then did it with macros which is not really satisfying (to much overhead!?, not very flexible). Is there a better solution?

My macro:

*-----; data test; name='A'; klasse=1; werta=1; wertb=2; output; name='A'; klasse=2; werta=11; wertb=22; output; name='B'; klasse=1; werta=111; wertb=221; output; run;

%macro x; %do k=1 %to 2; /* Need to know the range here */ data test&k; set test(where=(klasse=&k)); rename werta=werta&k. wertb=wertb&k.; /* Must be edited depending on the variables */ drop klasse; /* Must be edited depending on the 'class'-variable */ run; %end; data testsum; merge %do k=1 %to 2; /* Need to know the range again */ test&k. %end; ; by name; run;

%mend; %x; proc print; run; *-----;

Of cause I can do it with more macro-power but before doing so I'd like to know that I have to do it that way 'cause there is no easy way.

Tnx in advance.

Eckhard


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