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 (July 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 30 Jul 2009 16:01:02 -0400
Reply-To:     Pete <phlarsen@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Pete <phlarsen@YAHOO.COM>
Subject:      Re: UPDATE: Character/numeric issue when using ARRAY function...

On Thu, 30 Jul 2009 14:50:32 -0500, Joe Matise <snoopy369@GMAIL.COM> wrote:

>This is the implementation of my earlier suggestion. By the way, you should >have left this in one 'thread' - makes it easier for people to follow along. > >data example; > input project_ID Measure_Name $; >cards; >1111 boiler >1111 chiller >2222 lighting >2222 heating >3333 heating >4444 power >5555 furnace >5555 lamp >6666 exit signs >6666 lamp >6666 ballast >; >run; > >data have; >set example; >x=1; >run; > >proc transpose data=have out=want; >by project_id; >id measure_name; >var x; >run; > >data want_fin; >set want; >array vars _numeric_; >do _n_ = 1 to dim(vars); > if missing(vars[_n_]) then vars[_n_]=0; >end; >run; > >-Joe > >On Thu, Jul 30, 2009 at 2:45 PM, Pete <phlarsen@yahoo.com> wrote: > >> In short, how do I write this code so that the variables' names are based >> on >> the text values originally in work.example, but the values under each >> variable are "0" or "1" in numeric format (i.e., binomial coding)? Thanks. >> >> Here is some more information, including a simplified data example. I am >> using an ARRAY, because there are over a hundred unique text values in my >> real data (not simply nine variables as noted in this simplified dataset). >> >> data example; >> input project_ID Measure_Name $; >> cards; >> 1111 boiler >> 1111 chiller >> 2222 lighting >> 2222 heating >> 3333 heating >> 4444 power >> 5555 furnace >> 5555 lamp >> 6666 exit signs >> 6666 lamp >> 6666 ballast >> ; >> run; >> >> ***Transpose data; >> proc transpose data=work.example out=work.measures_trans (drop=_NAME_); >> by Project_ID ; >> id Measure_Name; >> var Measure_Name; >> run; >> >> ***Fix to format error but drops variable name; >> ***How do I write this code so that the variables names are based on the >> text values originally in work.example, but the values under each variable >> are "0" or "1" in numeric format?; >> >> data measures_trans (keep=Project_ID wan:); >> set measures_trans; >> array measure (*) boiler -- ballast; >> array want (9); >> do i = 1 to dim(measure); >> if missing(measure(i)) then want(i)=0; >> else want(i)=1; >> end; >> run; >>

Thank you, Joe (and everyone else), and sorry about breaking the "string" earlier.

Have a good one,

Pete


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