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 (May 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 12 May 2009 14:50:44 -0400
Reply-To:   Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:   Re: output question--one long row into many rows
Comments:   To: D T <sasandstats@live.com>
In-Reply-To:   <BLU132-W10E10F2DB35432340CA37AC8600@phx.gbl>
Content-Type:   text/plain; charset="us-ascii"

D.T.,

Just use the VLABEL function instead of VNAME. ;-)

Mike Rhoads RhoadsM1@Westat.com

-----Original Message----- From: D T [mailto:sasandstats@live.com] Sent: Tuesday, May 12, 2009 2:36 PM To: Mike Rhoads; sas-l@listserv.uga.edu Subject: RE: [SAS-L] output question--one long row into many rows

Mike,

thanks for this suggestion! Yes, you were correct: since I have many variables, I would prefer a more automated approach, and yours worked perfectly. What occurred to me after I saw your code is this: all my variables starting with "num" actually have explanatory labels--is there a way you are aware of that would let me put the label text into the code variable? I am thinking about this step:

code = substr(vname(_num[n]),4);

Thanks!

D.T.

> Date: Tue, 12 May 2009 13:38:06 -0400 > From: RHOADSM1@WESTAT.COM > Subject: Re: [SAS-L] output question--one long row into many rows > To: SAS-L@LISTSERV.UGA.EDU > > Since the original question indicates that there are many more variables than are listed in the example, you can streamline Mary's approach using arrays, the VNAME function (if a "code" variable is desired), and colon-style variable lists, assuming that the variables are systematically named and ordered as the question implies. > > data output_set; > set set1; > array _num {*} num: ; > array _pct {*} pct: ; > length code $ 8; /* or whatever length is needed */ > keep code num pct; > format pct 5.1; > if id=211 then do; > do n = 1 to dim(_num); > code = substr(vname(_num[n]),4); > num = _num[n]; > pct = _pct[n]; > output; > end; > end; > run; > > Mike Rhoads > RhoadsM1@Westat.com > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mary > Sent: Tuesday, May 12, 2009 11:56 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: output question--one long row into many rows > > > Try something like this (NOT tested) > > data output_set; > set set1; > if id=211 then > do; > code='a'; > num=numa; > pct=pcta > output; > code='lt'; > num=numlt; > pct=pctlt; > output; > num=numo; > pct=pcto; > output; > code='f'; > num=numf; > pct=pctf; > output; > end; > keep id code num pct; > run; > > > ----- Original Message ----- > From: "D T" <sasandstats@LIVE.COM> > To: <SAS-L@LISTSERV.UGA.EDU> > Sent: Tuesday, May 12, 2009 9:51 AM > Subject: output question--one long row into many rows > > > I have a data set like this (I am just showing some > variables, there are more): > > ID numa pcta numlt pctlt numo pcto numf > pctf > > 1 52 2.6 13 0.6 6 0.3 220 > 10.9 > > 2 13 0.6 101 5.0 11 2.1 13 > 0.7 > > [...] > > 211 905 4.0 732 3.6 87 3.3 1176 > 9.8 > > > > I need to output data for ID 211 only-this is a summary row. > I can use a proc print and get the information I need printed (one long row of output), but am wondering if there isn't way I can make the output more user-friendly. > > Here is what I would like to have in a table, if possible: > > numa pcta > > numlt pctlt > > numo pcto > > numf pctf > > .... etc. > > > > In terms of output, it would look like this for my example: > > 905 4.0 > > 732 3.6 > > 87 3.3 > > 1176 9.8 > > > > Can anyone think of an efficient way to code this output? > > > > Thanks! > > D.T. > > > _________________________________________________________________ > Hotmail(r) has ever-growing storage! Don't worry about storage limits. http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage1_052009=

________________________________ Windows Live(tm): Keep your life in sync. Check it out.<http://windowslive.com/explore?ocid=TXT_TAGLM_BR_life_in_synch_052009>


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