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 (March 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 Mar 2005 13:31:44 -0500
Reply-To:     Lingqun Liu <lingqun@gmail.com>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Lingqun Liu <lingqun@GMAIL.COM>
Subject:      Re: Question about data format
Comments: To: jn mao <jn_mao@yahoo.com>
In-Reply-To:  <20050315174237.98029.qmail@web41622.mail.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1

Use COPY statement and Proc transpose twice (you may need rename data set option also).

---------------------- sas code------------------------------------------ proc transpose data=sample out=result(drop=_name_); by id; id ques; var answ1 ; copy answ2; run; proc transpose data=result out=re(drop=_name_); by id; var answ2 ; copy q1-q3; run; -------------------------------------------------------------------------------------- Lingqun Liu

On Tue, 15 Mar 2005 09:42:36 -0800, jn mao <jn_mao@yahoo.com> wrote: > Thanks Terjeson and Toby. Actually, I have several variables for each question, so the original data like below: > data sample; > input id ques $ answ1 answ2; > cards; > 1 q1 3 12 > 1 q2 4 13 > 1 q3 3 15 > 2 q1 4 11 > 2 q2 4 14 > 2 q3 3 13 > 3 q1 3 15 > 3 q2 2 16 > 3 q3 4 17 > ; > > Then I want the final data format like: > > id answ1_q1 answ1_q2 answ1_q3 answ2_q1 answ2_q2 answ2_q3 > 1 3 4 3 12 13 15 > 2 4 4 3 11 14 13 > 3 3 2 4 15 16 17 > ; > > Can SAS recode the data to above format? I did try adding 'answ1' and 'answ2' after the statement 'var', but all data only use q1, q2, q3 as the top variable name so each id repeated twice for answ1 and answ2, like: > > id q1 q2 q3 > 1 3 4 3 > 1 12 13 15 > 2 4 4 3 > 2 11 14 13 > ; > > Thanks for the help. > > Jane > > > "Terjeson, Mark (IM&R)" <Mterjeson@russell.com> wrote: > Hi, > > Transpose is very handy for this: > BY becomes your left axis > ID becomes your top axis > VAR becomes the body > > data sample; > input id ques $ answ; > cards; > 1 q1 3 > 1 q2 4 > 1 q3 3 > 2 q1 4 > 2 q2 4 > 2 q3 3 > 3 q1 3 > 3 q2 2 > 3 q3 4 > ; > run; > > proc transpose data=sample out=result(drop=_name_); > by id; > id ques; > var answ; > run; > > Hope this is helpful. > > Mark Terjeson > Senior Programmer Analyst, IM&R > Russell Investment Group > > Russell > Global Leaders in Multi-Manager Investing > > --------------------------------- > Do you Yahoo!? > Yahoo! Small Business - Try our new resources site! >


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