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 (December 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 15 Dec 2006 12:31:57 -0800
Reply-To:     avi <aviben@BEZEQINT.NET.IL>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         avi <aviben@BEZEQINT.NET.IL>
Organization: http://groups.google.com
Subject:      Re: Horizontal Bar Chart ... in Proc REPORT !
Comments: To: sas-l@uga.edu
In-Reply-To:  <200612151734.kBFG1Bc3025938@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

"Richard A. DeVenezia" a écrit :

> In the spirit of the season, presented here is some sample code that uses Proc REPORT to grapically show within group percents. > > ------------------------------------------ > data foo; > do group = 1 to 4; > do seq = 1 to 1 + 6 * ranuni(10); > _n_ + 1; > rowid + 1; > y = floor (100 * (sqrt(seq) + log(_n_))); > y = round (100 * ranuni(123)); > output; > end; > end; > drop seq; > run; > > %macro create_bar_images > ( cback = cxffaaaa > , cfore = cxff0000 > , xpixels = 100 > , ypixels = 15 > ); > ods _all_ close; > > goptions reset=all gsfname=gfxpath goutmode=replace; > goptions device=gif xpixels=&xpixels. ypixels=&ypixels.; > > ods listing; > > %local workpath dir gfxpath; > %let workpath = %sysfunc(pathname(WORK)); > %let dir = %sysfunc(dcreate(gfxparts, &workpath.)); > %let gfxpath = %sysfunc(pathname(WORK))\gfxparts; > > filename gfxpath "&gfxpath."; > > %local notes; > %let notes = %sysfunc(getoption(notes)); > > options nonotes; > > data _null_; > W = input(getoption('xpixels'),best12.); > H = input(getoption('ypixels'),best12.); > > rc = gset ('catalog','work','bars'); > rc = ginit (); > > rc = gset ('WINDOW', 1, 1,1, W,H); > rc = gset ('TRANSNO', 1); > > rc = gset ('filtype', 'solid'); > > do left = 0 to 100; > name = cats('bar',left); > > rc = graph ('clear',name); > > rc = gset ('colrep',1,"&cback."); > rc = gset ('colrep',2,"&cfore."); > > rc = gset('FILCOLOR',1); > rc = gdraw('BAR',1,1, W,H); > > if left > 0 then do; > rc = gset('FILCOLOR',2); > rc = gdraw('BAR',1,1, left,H); > end; > > rc = graph ('update'); > end; > > rc = graph ('clear','blank'); > rc = graph ('update'); > > rc = gterm (); > run; > > options &notes.; > %mend; > > options mprint; > > %create_bar_images (cback=cxFDCD6F,cfore=cxEC9F04); > > ods html > file="%sysfunc(pathname(WORK))\myReport.html" > style=statistical > ; > > ods pdf > file="%sysfunc(pathname(WORK))\myReport.pdf" > style=statistical > ; > > ods listing; > > proc report nowindows data=foo > style(report)=[borderwidth=0 cellspacing=0 background=white cellpadding=4] > style(header)=[font_size=11pt] > ; > columns group y pct; > define group / order; > define y / analysis order=data ; > define pct / computed format=percent6.0 'Within/Group/%' ; > break before group / summarize ul ; > > compute y; > myCounter + 1; > > if myCounter = 1 then > ysum = y.sum; > > * use for debugging, esp. if a compute before section added; > * call execute(catx(' ','%put',myCounter,ysum,y.sum)); > > gfxpath = "%sysfunc(pathname(WORK))/gfxparts"; > > if myCounter > 1 then do; > pct = round(y.sum/ysum * 100); * y as percentage of group; > if pct < 0 then pct = 0; > else > if pct > 100 then pct = 100; > > imgfile = cats (gfxpath,'/bar',pct,".gif"); > gpct = pct; > end; > else do; > imgfile = cats (gfxpath,'/',"blank.gif"); > gpct = 100; > end; > > style = 'style=[' > || ' posttext=" "' > || ' postimage=' || quote(trim(imgfile)) > || ']' > ; > > call define (_col_,'style',style); > endcomp; > > compute pct; > pct = gpct / 100; > endcomp; > > compute after group; > line ' '; > myCounter = 0; > endcomp; > run; > > ods _all_ close; > > dm 'log' log; > ------------------------------------------ > > Richard A. DeVenezia > http://www.devenezia.com


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