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 (January 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 7 Jan 2011 13:03:33 -0500
Reply-To:     Peter <phlarsen@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter <phlarsen@YAHOO.COM>
Subject:      Re: Misc. SAS Gplot/Greplay Questions

Thanks, Ya, you were VERY helpful and everything looks good. Have a nice weekend. -Peter

On Thu, 6 Jan 2011 14:59:30 -0500, Ya Huang <ya.huang@AMYLIN.COM> wrote:

>Ok, here is a better solution. In stead of using format and font to >control the y label width, we can control the X axis width with length >option, then use origin option to make sure both plot start at the >same origin. I changed the var color to col, to avoid conflit with >color var in anno dataset. Thie version also dropped the ftext='Courier', >so the font is proportional. The cost of this is the left side have >bigger space: > > > >%macro gph(num); > >*****Creating percentiles for labeling; >PROC UNIVARIATE DATA=graph&num. NOprint; >BY Strategy; VAR Score; >OUTPUT OUT=Pctls_graph&num. N=count pctlpts=20 50 80 > pctlpre=sc_ pctlname=P20 P50 P80; >run; > >DATA Pctls_graph&num.; >SET Pctls_graph&num.; >compare=sc_p50; >col=(compare > 100); >run; > >DATA Pctls_graph&num.; >SET Pctls_graph&num.; >KEEP Strategy iqr compare col; >iqr =sc_p20; OUTPUT; >iqr =sc_p50; OUTPUT; >iqr =sc_p80; OUTPUT; >RUN; > >data anno; > set Pctls_graph&num.; > diff=iqr-compare; >run; > >/* Create the annotate data set */ >data anno; > /* Set the length of variables */ > length function color $8; > length text $3; > > /* Use the data coordinate system; position above and right aligned. */ > /* Apply annotation after procedure output. */ > retain xsys '2' ysys '2' position '6' when 'a'; > set anno; > > /* Label the data point */ > function='label'; > x=strategy+(.2); y=iqr; > text=(put(iqr,3.)); > style="TimesRoman"; > size=5; >run; > >data anno; > set anno; > if diff ne 0 then do; > text=""; > end; >run; > >goptions reset=all; > >symbol1 interpol=boxf20 cv=red ci=red co=ligr width=2 bwidth=9; >symbol2 interpol=boxf20 cv=blue ci=red co=ligr width=2 bwidth=9; > > >AXIS1 style=3 offset=(7,7) value=none label=none major=none minor=none >length=5in origin=(25pct,); > >AXIS2 /*order=&miniqr. to &maxiqr. by &rangeiqr.*/ label=(h=.05 '') >minor=none major=(height=1) value=(height=4); > >PROC GPLOT DATA=Pctls_graph&num.; >%if &num. = 1 %then %do; >format iqr dollar6.; >%end; >%if &num. = 2 %then %do; >format iqr percent8.; >%end; >PLOT iqr * Strategy =col / anno=anno frame Haxis=axis1 vaxis=axis2 >cframe=ligr nolegend; >RUN; >QUIT; > >%mend; >%gph (1); >%gph (2); > >goptions reset=all rotate=portrait device=emf xmax=5 ymax=8.25 >ftext="TimesRoman" gsfname=output gsfmode=replace; >filename output "Pete.emf"; > >proc greplay igout=work.gseg gout=work.gseg tc=work.tmplt nofs; >tdef PK1 1 / llx=0 lly=50 /*first panel*/ > ulx=0 uly=100 > lrx=100 lry=50 > urx=100 ury=100 > 2 / llx=0 lly=0 /*second panel*/ > ulx=0 uly=50 > lrx=100 lry=0 > urx=100 ury=50 > >; >run; >quit; > >proc greplay igout=work.gseg gout=work.gseg tc=work.tmplt nofs; >template PK1; >treplay 1:gplot >2:gplot1 >; >quit; > > > > > > > >On Thu, 6 Jan 2011 13:44:13 -0500, Peter <phlarsen@YAHOO.COM> wrote: > >>Hi Again- >> >>Thanks for the suggestions, Ya, but something is still amiss with respect >>to the alignment issue. >> >>QUESTION 1: I gave you some basic dummy data in my example program, but >>when I ran your suggested fix on my real data things didn't work out so >>well. Here is a great example....if the top graph y-axis format >>is "dollar3." this allows SAS to display two digit numbers with a dollar >>sign ($) in front (e.g., $25). If the bottom graph is "percent." with >>length=3 (e.g., 25%), then the top and bottom graphs are mis-aligned. >>This is weird, because both values appear to be 3 characters wide. >> >>DO YOU THINK I HAVE TO CREATE A NEW FORMAT USING PROC FORMAT TO ADDRESS >>THIS ISSUE? >> >>QUESTION 3: Is it possible to color individual boxplots differently if >>within a single GPLOT? For example, if I have three boxplots next to each >>other in a single graph....can I color each one a different color? >> >>Many thanks for all of your help. >> >>-Pete >> >> >> >> >>On Wed, 5 Jan 2011 23:33:26 -0500, Ya Huang <ya.huang@AMYLIN.COM> wrote: >> >>>Q1: >>> >>>The mis-alignment is caused by the different format width for y variables >>>in plot 1 and 2. A little adjustment can solve both 1 & 2 problems: >>> >>>%if &num. = 1 %then %do; >>>format iqr dollar4.; >>>%end; >>>%if &num. = 2 %then %do; >>>format iqr 3.; >>>%end; >>> >>>Q2: >>> >>>The wider of the format, the wider left side white area is. Make the >>>format width as smalle as possible, so it won't take too much space. >>>You can alse change the font size. >>> >>>Q3: >>>Not sure what sample size is. >>> >>>Q4: >>>Change device to SASEMF and use ODS/RTF will get you best image quality. >>> >>> >>>HTH >>> >>>Ya >>> >>>On Wed, 5 Jan 2011 20:10:35 -0500, Peter the SAS Hack <phlarsen@YAHOO.COM> >>>wrote: >>> >>>>Hi Folks- >>>> >>>>Its been a while since I last posted. I know how you love seeing example >>>>code, so I am going to include a nearly-complete example program. Here >>>>are my questions: >>>> >>>>1. I am creating a pair of stacked box plots using GREPLAY, but the >>>>length of the values displayed in the y-axis is causing my stacked graphs >>>>to be slightly mis-aligned (i.e., the first box plot within graph#1 >>should >>>>be right over the first box plot in graph#2. and so on...) >>>> >>>>QUESTION: Is there a way to get SAS to align the graphics areas perfectly >>>>on top of each other so that each box plot is on top of the other? >>>> >>>>2. The program creates an EMF file, but I noticed that there is a blank >>>>area to the left of the graphs that is at least an inch wide. Currently, >>>>I am cropping this blank area in MS Word. >>>> >>>>QUESTION: Is there a way to remove this blank space before the GREPLAY >>>>exports the results to EMF? >>>> >>>>3. The program currently creates boxplots within a single gplot >>statement >>>>that all have the same color. >>>> >>>>QUESTION: Is is possible to color the individual box plots differently >>>>within a single gplot based on sample size (e.g., if sample size is >>>>greater than 3 can I color it red and all of the other boxplots within a >>>>single gplot blue)? >>>> >>>>4. I am sending these results into MS Word. >>>> >>>>QUESTION: Will using the ODS functionality make my images crisper and >>>>will I be able to use TrueType fonts like Times New Roman? If so, can >>you >>>>provide some example code? >>>> >>>>As always, code adjustments to any and all of the above questions are >>>>greatly appreciated. For your effort, you get some working stacked graph >>>>examples to play around with..... >>>> >>>>Thanks everyone, >>>> >>>>Pete "The Hack" >>>> >>>>************CODE EXAMPLE***************; >>>>options nobyline; >>>> >>>>data graph1; >>>> input Metric $ Strategy Score; >>>> datalines; >>>>Cost 1 4 >>>>Cost 1 7 >>>>Cost 1 3 >>>>Cost 2 4 >>>>Cost 2 7 >>>>Cost 2 8 >>>>Cost 3 5 >>>>Cost 3 6 >>>>Cost 3 8 >>>>Cost 4 5 >>>>Cost 4 6 >>>>Cost 4 8 >>>>Cost 5 5 >>>>Cost 5 6 >>>>Cost 5 8 >>>>Cost 5 9 >>>>Cost 5 9 >>>>Cost 5 9 >>>>; >>>>run; >>>> >>>>data graph2; >>>> input Metric $ Strategy Score; >>>> datalines; >>>>Savings 1 155 >>>>Savings 1 3 >>>>Savings 1 36 >>>>Savings 2 253 >>>>Savings 2 74 >>>>Savings 2 55 >>>>Savings 3 50 >>>>Savings 3 600 >>>>Savings 3 200 >>>>Savings 4 50 >>>>Savings 4 600 >>>>Savings 4 200 >>>>Savings 5 50 >>>>Savings 5 600 >>>>Savings 5 200 >>>>; >>>>run; >>>> >>>> >>>>proc greplay igout=work.gseg nofs; >>>>delete _all_; >>>>run; >>>> >>>>%macro gph(num); >>>> >>>>*****Creating percentiles for labeling; >>>>PROC UNIVARIATE DATA=graph&num. NOprint; >>>>BY Strategy; VAR Score; >>>>OUTPUT OUT=Pctls_graph&num. N=count pctlpts=20 50 80 >>>> pctlpre=sc_ pctlname=P20 P50 P80; >>>>run; >>>> >>>>DATA Pctls_graph&num.; >>>>SET Pctls_graph&num.; >>>>compare=sc_p50; >>>>run; >>>> >>>>DATA Pctls_graph&num.; >>>>SET Pctls_graph&num.; >>>>KEEP Strategy iqr compare; >>>>iqr =sc_p20; OUTPUT; >>>>iqr =sc_p50; OUTPUT; >>>>iqr =sc_p80; OUTPUT; >>>>RUN; >>>> >>>>data anno; >>>> set Pctls_graph&num.; >>>> diff=iqr-compare; >>>>run; >>>> >>>>/* Create the annotate data set */ >>>>data anno; >>>> /* Set the length of variables */ >>>> length function color $8; >>>> length text $3; >>>> >>>> /* Use the data coordinate system; position above and right aligned. */ >>>> /* Apply annotation after procedure output. */ >>>> retain xsys '2' ysys '2' position '6' when 'a'; >>>> set anno; >>>> >>>> /* Label the data point */ >>>> function='label'; >>>> x=strategy+(.2); y=iqr; >>>> text=(put(iqr,3.)); >>>> style="TimesRoman"; >>>> size=5; >>>>run; >>>> >>>>data anno; >>>> set anno; >>>> if diff ne 0 then do; >>>> text=""; >>>> end; >>>>run; >>>> >>>>symbol1 interpol=boxf20 cv=red ci=red co=ligr width=2 bwidth=9; >>>> >>>>AXIS1 style=3 offset=(7,7) value=none label=none major=none minor=none; >>>> >>>>AXIS2 /*order=&miniqr. to &maxiqr. by &rangeiqr.*/ label=(h=.05 '') >>>>minor=none major=(height=1) value=(height=4); >>>> >>>>PROC GPLOT DATA=Pctls_graph&num.; >>>>%if &num. = 1 %then %do; >>>>format iqr dollar6.; >>>>%end; >>>>%if &num. = 2 %then %do; >>>>format iqr 3.; >>>>%end; >>>>PLOT iqr * Strategy / anno=anno frame Haxis=axis1 vaxis=axis2 >>cframe=ligr; >>>>RUN; >>>>QUIT; >>>> >>>>%mend; >>>>%gph (1); >>>>%gph (2); >>>> >>>>goptions reset=all rotate=portrait device=emf xmax=5 ymax=8.25 >>>>ftext="TimesRoman" gsfname=output gsfmode=replace; >>>>filename output "Pete.emf"; >>>> >>>>proc greplay igout=work.gseg gout=work.gseg tc=work.tmplt nofs; >>>>tdef PK1 1 / llx=0 lly=50 /*first panel*/ >>>> ulx=0 uly=100 >>>> lrx=100 lry=50 >>>> urx=100 ury=100 >>>> 2 / llx=0 lly=0 /*second panel*/ >>>> ulx=0 uly=50 >>>> lrx=100 lry=0 >>>> urx=100 ury=50 >>>> >>>>; >>>>run; >>>>quit; >>>> >>>>proc greplay igout=work.gseg gout=work.gseg tc=work.tmplt nofs; >>>>template PK1; >>>>treplay 1:gplot >>>>2:gplot1 >>>>; >>>>quit;


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