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 (August 2011, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 11 Aug 2011 09:56:42 -0700
Reply-To:     Daniel Nordlund <djnordlund@FRONTIER.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Daniel Nordlund <djnordlund@FRONTIER.COM>
Subject:      Re: failing to transpose a set from wide to long using array
              statement
In-Reply-To:  <201108111630.p7BG1l55010695@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="UTF-8"

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Cornel Lencar > Sent: Thursday, August 11, 2011 9:31 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: failing to transpose a set from wide to long using array > statement > > Hi, > > I have an issue with converting a wide dataset to a long dataset. I have a > two groups of variables (postal codes and groupings, for a period of 9 > years), both sets character varibles, that need to be put on a long form > and when I am trying to do that using the array statement, I get the error > message that these variables were defined as both character and numeric. I > am sending a snippet with the code that I used, the output of the proc > contents describing the dataset that I want to transpose and the log > message with the error prompt. Any suggestion would be greately > apreciated. > > options obs=1000; > data cox; > set raw.cox_all_wide(keep=phnnum PC2000 PC2001 PC2002 PC2003 PC2004 PC2005 > PC2006 PC2007 PC2008 > GRPC2000 GRPC2001 GRPC2002 GRPC2003 GRPC2004 GRPC2005 GRPC2006 GRPC2007 > GRPC2008 time_chf); > run; > > proc contents data=cox;run; > > data cox_long; > LENGTH PCODE $ 6 GROUPC $ 2; > > ARRAY PC(9) PC2000 PC2001 PC2002 PC2003 PC2004 PC2005 PC2006 > PC2007 PC2008; > ARRAY GRPC(9) GRPC2000 GRPC2001 GRPC2002 GRPC2003 GRPC2004 > GRPC2005 GRPC2006 GRPC2007 GRPC2008; > set cox; > do year=1 to time_chf; > PCODE = PC(year); > GROUPC = GRPC(year); > output; > end; > run; > > > 5 options obs=1000; > 6 data cox; > 7 set raw.cox_all_wide(keep=phnnum PC2000 PC2001 PC2002 PC2003 PC2004 > 7 ! PC2005 PC2006 PC2007 PC2008 > 8 GRPC2000 GRPC2001 GRPC2002 GRPC2003 GRPC2004 GRPC2005 GRPC2006 > 8 ! GRPC2007 GRPC2008 time_chf); > 9 run; > > NOTE: There were 1000 observations read from the data set > RAW.COX_ALL_WIDE. > NOTE: The data set WORK.COX has 1000 observations and 20 variables. > NOTE: DATA statement used (Total process time): > real time 2.67 seconds > cpu time 0.01 seconds > > > The SAS System > > The CONTENTS Procedure > > Data Set Name WORK.COX Observations 1000 > Member Type DATA Variables 20 > Engine V9 Indexes 0 > Created Thursday, August 11, Observation Length 88 > 2011 09:07:32 AM > Last Modified Thursday, August 11, Deleted Observations 0 > 2011 09:07:32 AM > Protection Compressed NO > Data Set Type Sorted NO > Label > Data Representation WINDOWS_32 > Encoding wlatin1 Western > (Windows) > > > Engine/Host Dependent Information > > Data Set Page Size 8192 > Number of Data Set Pages 12 > First Data Page 1 > Max Obs per Page 92 > Obs in First Data Page 59 > Number of Data Set Repairs 0 > File Name h:\sas\sas9work\_TD5516\cox.sas7bdat > Release Created 9.0101M3 > Host Created WIN_PRO > > > Alphabetic List of Variables and Attributes > > # Variable Type Len Format Informat Label > > 11 GRPC2000 Char 2 > 12 GRPC2001 Char 2 > 13 GRPC2002 Char 2 > 14 GRPC2003 Char 2 > 15 GRPC2004 Char 2 > 16 GRPC2005 Char 2 > 17 GRPC2006 Char 2 > 18 GRPC2007 Char 2 > 19 GRPC2008 Char 2 > 2 PC2000 Char 6 > 3 PC2001 Char 6 > 4 PC2002 Char 6 > 5 PC2003 Char 6 > 6 PC2004 Char 6 > 7 PC2005 Char 6 > 8 PC2006 Char 6 > 9 PC2007 Char 6 > 10 PC2008 Char 6 > 1 PHNNUM Num 8 13. 13. Person Health Number > 20 TIME_CHF Num 8 > > > > 102 data cox_long; > 103 LENGTH PCODE $ 6 GROUPC $ 2; > 104 > 105 ARRAY PC(9) PC2000 PC2001 PC2002 PC2003 PC2004 PC2005 PC2006 > 105! PC2007 PC2008; > 106 ARRAY GRPC(9) GRPC2000 GRPC2001 GRPC2002 GRPC2003 GRPC2004 > 106! GRPC2005 GRPC2006 GRPC2007 GRPC2008; > 107 set cox; > ERROR: Variable PC2000 has been defined as both character and numeric. > ERROR: Variable PC2001 has been defined as both character and numeric. > ERROR: Variable PC2002 has been defined as both character and numeric. > ERROR: Variable PC2003 has been defined as both character and numeric. > ERROR: Variable PC2004 has been defined as both character and numeric. > ERROR: Variable PC2005 has been defined as both character and numeric. > ERROR: Variable PC2006 has been defined as both character and numeric. > ERROR: Variable PC2007 has been defined as both character and numeric. > ERROR: Variable PC2008 has been defined as both character and numeric. > ERROR: Variable GRPC2000 has been defined as both character and numeric. > ERROR: Variable GRPC2001 has been defined as both character and numeric. > ERROR: Variable GRPC2002 has been defined as both character and numeric. > ERROR: Variable GRPC2003 has been defined as both character and numeric. > ERROR: Variable GRPC2004 has been defined as both character and numeric. > ERROR: Variable GRPC2005 has been defined as both character and numeric. > ERROR: Variable GRPC2006 has been defined as both character and numeric. > ERROR: Variable GRPC2007 has been defined as both character and numeric. > ERROR: Variable GRPC2008 has been defined as both character and numeric. > 108 do year=1 to time_chf; > 109 PCODE = PC(year); > 110 GROUPC = GRPC(year); > 111 output; > 112 end; > 113 run; > > NOTE: Numeric values have been converted to character > values at the places given by: (Line):(Column). > 109:18 110:19 > NOTE: The SAS System stopped processing this step because of errors. > WARNING: The data set WORK.COX_LONG may be incomplete. When this step > was stopped there were 0 observations and 23 variables. > WARNING: Data set WORK.COX_LONG was not replaced because this step was > stopped. > NOTE: DATA statement used (Total process time): > real time 0.67 seconds > cpu time 0.00 seconds

Just place your ARRAY definitions after the set statement instead of before.

data cox_long; LENGTH PCODE $ 6 GROUPC $ 2;

set cox; ARRAY PC(9) PC2000 PC2001 PC2002 PC2003 PC2004 PC2005 PC2006 PC2007 PC2008; ARRAY GRPC(9) GRPC2000 GRPC2001 GRPC2002 GRPC2003 GRPC2004 GRPC2005 GRPC2006 GRPC2007 GRPC2008; do year=1 to time_chf; PCODE = PC(year); GROUPC = GRPC(year); output; end; run;

Hope this is helpful,

Dan

Daniel Nordlund Bothell, WA USA


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