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 2010, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 26 Mar 2010 16:33:53 -0400
Reply-To:     msz03@albany.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Zdeb <msz03@ALBANY.EDU>
Subject:      Re: Changing formats on Transpose dataset
Content-Type: text/plain;charset=iso-8859-1

hi ... and just to add a bit to Nat's solution ...

if you want MRV to be UPCASE, just use an UPCASE informat

the STRIP function takes away leading and trailing blanks but if you use ": $42." you are using LIST rather than FORMATTED input and the variable value will not have any leading blanks no matter what you do, there are trailing blanks since the length of the variable INFMT is 42 so, just use ": $42." instead of "$char42." and STRIP

data test; infile datalines truncover; input suid : $2. mrv : $upcase32. Response :$500. infmt : $42.; datalines; 1 HH1 1 1. 1 HH2 22 7.2 1 SC1 Yes $char25. 2 HH1 5 1. 2 HH2 10 7.2. 2 SC1 No $char25. ; run;

-- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475

> Bill > > Since you are transposing character data, all of your new columns are character. In order for HH1 and HH2 to have numeric formats, they must become > numeric variables. Hence: > > data test; > infile datalines truncover; > input suid :$2. mrv :$32. Response :$500. infmt $char42.; > mrv= upcase(mrv); > infmt = strip(infmt); > datalines; > 1 HH1 1 1. > 1 HH2 22 7.2 > 1 SC1 Yes $char25. > 2 HH1 5 1. > 2 HH2 10 7.2. > 2 SC1 No $char25. > ; > run ; > > **** convert the vertical table to a horizontal table ; > proc transpose data=test out=testpose (drop=_label_ _name_ > rename = ( HH1 = CHH1 HH2 = CHH2 )); > by suid ; > id mrv ;* equal sign removed here as well as next line; > var response ; > > > run ; > > Data Final; > set testpose ; > HH1 = input ( Chh1 , 8. ); > HH2 = input ( CHH2 , 8. ); > > format HH1 1. HH2 7.2 SC1 $char25.; > > drop chh: ; > > run; > > Nat Wooding > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Bill Krause > Sent: Friday, March 26, 2010 3:15 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Changing formats on Transpose dataset > > I am using Proc Transpose to convert a vertical table called test. > > In the vertical table under a column called mrv is a list of variable > names. In the column called infmt is the format for the mrv response value. > > The original table(test) has a format for the response value set to $500. > > **** create vertical table ; > data test; > infile datalines truncover; > input suid :$2. mrv :$32. Response :$500. infmt $char42.; > mrv= upcase(mrv); > infmt = strip(infmt); > datalines; > 1 HH1 1 1. > 1 HH2 22 7.2 > 1 SC1 Yes $char25. > 2 HH1 5 1. > 2 HH2 10 7.2. > 2 SC1 No $char25. > ; > run ; > > **** convert the vertical table to a horizontal table ; > proc transpose data=test out=testpose (drop=_label_ _name_ ) ; > by suid ; > id=mrv ; > var=response ; > run ; > > So file(testpose) will look like: > suid HH1 HH2 SC1 > 1 1 22 Yes > 2 5 10 No > > > What I need to change the informat/format on the TRANSPOSED file for the > REPLY from $500. to the respective informat/format given in the infmt. > > The format of the horizontal table should be : > It should be: > HH1 1. > HH2 7.2 > SC1 $char25. > > Instead of: > HH1 $500. > HH2 $500. > SC1 $500. > > > Thanks for your assistance. > > > Bill K. > wkrause2003@yahoo.com > CONFIDENTIALITY NOTICE: This electronic message contains > information which may be legally confidential and or privileged and > does not in any case represent a firm ENERGY COMMODITY bid or offer > relating thereto which binds the sender without an additional > express written confirmation to that effect. The information is > intended solely for the individual or entity named above and access > by anyone else is unauthorized. If you are not the intended > recipient, any disclosure, copying, distribution, or use of the > contents of this information is prohibited and may be unlawful. If > you have received this electronic transmission in error, please > reply immediately to the sender that you have received the message > in error, and delete it. Thank you. >


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