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 (March 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 28 Mar 2006 06:02:30 -0800
Reply-To:   lzhang9830@YAHOO.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Lei Zhang <lzhang9830@YAHOO.COM>
Organization:   http://groups.google.com
Subject:   Re: How to create a "%picture" macro?
Comments:   To: sas-l@uga.edu
In-Reply-To:   <1143517362.289719.104670@u72g2000cwu.googlegroups.com>
Content-Type:   text/plain; charset="iso-8859-1"

Thanks, Shiling ! What you suggested might be a good way for creating adhoc "%picture"macros for various special situations. This might lead to many small macros of this type, which will be often hard to reuse. What I am looking for is a single generic macro that can create various formating string with one type of macro call. I think the key part is how to parsing and assembling the format contents provided by fmt=.

LZ

shiling99@yahoo.com wrote: > Zhang, > > Here is an example to illustrate the idea, you may modify as needed. > > Hope this helps. > > 1 proc format; > 2 picture num(round) > 3 low-high = "0000000009)" ( prefix = "(" ) > 4 ; > NOTE: Format NUM has been output. > 5 picture pct(round) > 6 low-high = "0000000009.0%)" ( prefix = "(" ) > 7 ; > NOTE: Format PCT has been output. > 8 run; > > NOTE: PROCEDURE FORMAT used (Total process time): > real time 0.12 seconds > cpu time 0.02 seconds > > > 9 run; > 10 > 11 %macro putpic(num,pct); > 12 cats(put(&num,num.),put(&pct,pct.)) > 13 %mend; > 14 > 15 data _null_; > 16 do i = 1 to 10; > 17 num=ranuni(100)*50; > 18 pct=ranuni(100)*30; > 19 num_pct=%putpic(num,pct); > 20 put num pct num_pct; > 21 end; > 22 run; > > 24.81284911 0.2661469533 (25)(0.3%) > 49.121530447 28.19593613 (49)(28.2%) > 8.0128893294 27.832049256 (8)(27.8%) > 14.895865747 5.0751684583 (15)(5.1%) > 48.97013104 19.699654803 (49)(19.7%) > 46.592852891 11.611564407 (47)(11.6%) > 16.971554266 21.553730388 (17)(21.6%) > 35.119288035 21.581892451 (35)(21.6%) > 13.058945333 29.788892786 (13)(29.8%) > 33.824312074 19.522555638 (34)(19.5%) > NOTE: DATA statement used (Total process time): > real time 0.01 seconds > cpu time 0.02 seconds > > > lzhang9830@yahoo.com wrote: > > Hi All, > > I would like to create a "%picture" macro that will extend SAS > > picture format functionality to multiple numeric variables. The > > %picture has two parameters like this > > > > %picture(VAR1 VAR2.. VARn, fmt= xx or xx.x with other special > > characters such as ( ) % ) > > > > Here are some examples of %picture usage: > > > > 1. %picture(138 35.4, fmt=xxx (xx.x%) ) ==> 138 (35.4%) > > > > 2. %picture(22.3 21. 7 24.6 fmt=xx.x [xx.x, xx.x]) ==> 22.3 [21.7, > > 24.6] > > > > 3. %picture(11 100, fmt=xx/xxx) ==> 11/100 > > > > The %picture is actually similiar to the Printf (..) function in > > C or C++ if you know C /C++ langauges. You may change the style of > > macro parameter style if you like. I am just looking for an easy > > solution for this type of macro. Your help and advice will be very > > much appreciated. Thanks. > > > > LZ


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