Date: Wed, 3 Dec 2008 16:56:27 -0500
Reply-To: Akshaya Nathilvar <akshaya.nathilvar@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Akshaya Nathilvar <akshaya.nathilvar@GMAIL.COM>
Subject: Re: Proc Transpose - long to wide
Content-Type: text/plain; charset=ISO-8859-1
Proc transpose and rename option will help:
Proc transpose data=have out=want(drop=_name_ rename=(col1= col2= col3=));
by id seq;
On Wed, Dec 3, 2008 at 4:46 PM, sas 9 bi user <email@example.com> wrote:
> I have the below data, I need to reshape it and have spent far too long
> trying and thought you all could assist.
> The data is survey data, so a person can take multiple surveys during one
> phone call. Each person is given a unique person ID and then a sequence
> number. There is also a survey code to differentiate the survey and then
> their responses (string values).
> This is what the data looks like in the 'Have' dataset below. In my 'Want'
> dataset that is how I want it to look when converted to wide. Some
> questions can have null responses which is reflected in my last record in
> have below. I need to allow for null responses.
> Thanks in advance for your suggestions!
> data have;
> length type_of_question $10 response $20;
> input id seq question_number type_of_question $ response $;
> 100 1 1 Health 3
> 100 1 2 Health Good
> 100 1 1 Family 2
> 100 1 2 Family Great
> 100 2 1 Health 1
> 100 2 2 Health Bad
> 100 2 1 Family 9
> 100 2 2 Family
> data want;
> length Health_response_1 $20 Health_response_2 $20 Family_response_1 $20
> Family_response_2 $20;
> input id seq Health_response_1 Health_response_2 Family_response_1
> 100 1 3 Good 2 Great
> 100 2 1 Bad 9