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 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 16 Aug 2007 13:53:53 -0700
Reply-To:     Jack Hamilton <kd6ttl@FASTMAIL.FM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <kd6ttl@FASTMAIL.FM>
Subject:      Re: Proc means
Comments: To: toby dunn <tobydunn@hotmail.com>
In-Reply-To:  <BAY123-F18CE78570CDDA21DEC64A1DEDF0@phx.gbl>
Content-Type: text/plain; charset="ISO-8859-1"

Most people never use proc transpose. They will at least be exposed to PROC REPORT if they take a reporting class or go to a regional user group meeting. Ever seen a tutorial on PROC TRANSPOSE? I haven't, but training on PROC REPORT is easy to find. It's one of the core procedures in base SAS, along with PRINT, SUMMARY/MEANS, and FREQ, which every SAS programmer should be able to use.

My PROC REPORT solution is 12 lines. If I jammed as much code into each line as possible, instead of formatting it to be easier to read, it would be shorter. Art's solution with PROC TRANSPOSE is 17 lines.

The original poster mentioned PROC PRINT, so it's reasonable to assume that some kind of print output is desired.

You are correct that the output data set is not quite what was requested. But perhaps it would be sufficient - it's trivial to transform into the correct format if you know the number of months in advance.

I think PROC TRANSPOSE is the most difficult procedure to understand of the non-stat, non-graph base procs. In many years of SAS programming, I have managed to find a use for it only a few times - literally fewer than a half dozen - whereas I have used PROC TABULATE and PROC REPORT scores or hundreds of times.

On Thu, 16 Aug 2007 13:58:59 +0000, "toby dunn" <tobydunn@hotmail.com> said: > Okay Jack I like you and all but how on earth is a proc tabulate or > report > which most people only ever use to produce a report easier to follow than > a > proc transpose? Not to mention with eiether one it requires more typing > and > forcing a reporting procedure to produce a data set which neither one is > quit what is needed. > > > > Toby Dunn > > > Two wrongs are only the beginning. > > Success always occurs in private and failure in full view. > > Experience is something you don't get until just after you need it. > > > > > > From: Jack Hamilton <jfh@STANFORDALUMNI.ORG> > Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG> > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Proc means > Date: Wed, 15 Aug 2007 22:33:33 -0700 > > I avoid PROC TRANSPOSE whenever possible, and it's almost always > possible. > > In this case, I would try to change the requirements so I could use PROC > TABULATE or PROC REPORT instead: > > ===== > data have; > set sashelp.orsales; > month = 'month' || substr(quarter,6,1); > run; > > proc tabulate data=have out=havetab missing; > class product_category month; > var total_retail_price; > tables product_category='', > total_retail_price=''*mean=''*month='' > / box=product_category; > run; > > proc report data=have > out=havereport (drop=_break_) > missing nofs; > columns product_category month , total_retail_price; > define product_category / group "Product_Category"; > define month / across " "; > define total_retail_price / mean " "; > run; > ===== > > PROC TABULATE produces the right print output, but the output data set > is in the wrong form. > > PROC REPORT comes pretty close to the right print output (there are some > extra blank spaces) and the output data set is right except for the > variable names. > > Either way, the program is easier to follow than with the PROC TRANSPOSE > solution. > > > > On Wed, 15 Aug 2007 18:11:06 -0400, "Arthur Tabachneck" > <art297@NETSCAPE.NET> said: > > Adriano, > > > > While I liked Peter's paper, I agree with Toby that a simple transpose > > would give you exactly what you want. For example: > > > > data have; > > set sashelp.orsales; > > month=substr(quarter,6,1); > > run; > > > > proc sort data=have; > > by product_category month; > > run; > > > > proc means data=have (where=(total_retail_price gt 0)); > > var total_retail_price; > > by product_category month; > > output out=temp (drop=_:) mean=; > > run; > > > > proc transpose data=temp out=want (drop=_:) prefix=month; > > var total_retail_price; > > by product_category; > > id month; > > run; > > > > HTH, > > Art > > ----------- > > On Wed, 15 Aug 2007 16:52:10 -0700, Adriano Rodrigues - Instituto GPP > > <adriano@GPP.COM.BR> wrote: > > > > >Hi all, > > > > > >I have on file with variables: > > >company product number date and price. > > > > > >i want just make means for prices per company/product/material/month > > > > > >like: > > >proc means data=simp maxdec=2; > > > > > >var pricef; > > > > > >class company product material month; > > > > > >where pricef>0; > > > > > >run; > > > > > >But i wanted results by month in columms not like proc means shows. > > > > > >i wanted output like > > > > > >company product material month1 month2 month3 > > > > > > 3.02 3.15 3.17 > > > > > >and not how appear > > > > > >company product material month1 3.02 > > > > > > month2 3.15 > > > > > > month3 3.17 > > > > > > > > > > > >how to do that with proc means? or i need output someway data and make > > >simple proc print? > > > > > >thanks in advance, > > > > > >Adriano > -- > Jack Hamilton > Sacramento, California > jfh@alumni.stanford.org > > _________________________________________________________________ > Now you can see trouble…before he arrives > http://newlivehotmail.com/?ocid=TXT_TAGHM_migration_HM_viral_protection_0507 > >


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