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 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 29 Mar 2006 07:33:53 -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
Content-Type:   text/plain; charset="iso-8859-1"

Hi Toby,

Good questions !

I was a C/C++ programmer several years ago. I think C-type function such as printf is very useful for generating parameterized formatted mesages either in SAS Macro or SAS data step. For example,

Instead of using

" trim(left(put(var1, 8.1)||"["||trim(left(put(var2, 7.5)))||","||trim(left(put(var3, 8.7))||"]"

to create formatted string 8.1 [ 7.5, 8.7], I would prefer to use a "picture" macro like

s= %picture(var1 var2 var3, fmt=xx.x [xx.x, xx.x])

It is easy to use and understand !.

For the questions you raised about unequal number of variables and formats in a macro call. I think we can either report this is an error, or just match what they can and let users to fix the macro calls later after they see the result string.

I would like this macro to run on SAS version 8.02 and up. Since both versions have functions to support regular expression handling (REGEX) functions, I think they will make the implementation a little easy.

For how to use SAS regex functions, I just noticed a good paper " An Introduction to Perl Regular Expressions" in SUGI 31 by Ronald Cody. I guess %picture could be a good exercise of using SAS REGEX funtions described by Ronald .

Talk you later

Have fun

LZ

toby dunn wrote: > Lei , > > What value do you see in this approach over either creating a user format or > just typing what you want into where ever you want it to go? > > But even say you have a good reason, lets consider the possibilities: > > 1.) You have an equal number of values in your value list to the number of > formats in your format list. Not a problem I think we get what you want > here. > > 2.) You have more values in your value list than in your format list, which > value goes with value then? > > 3.) You have more formats in your format list than in your value list, again > which value ges with what value? > > 4.) you have either no values in your value list or you have no formats in > your format list? > > Finally what version of SAS would you like this to run on V8 or some flavor > of V9? > And > in what context would you like to call this macro? > > > > > > Toby Dunn > > > > > > From: Lei Zhang <lzhang9830@YAHOO.COM> > Reply-To: lzhang9830@YAHOO.COM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: How to create a "%picture" macro? > Date: Tue, 28 Mar 2006 16:25:00 -0800 > > Hi, > I am looking for a macro that can work with both VAR and VAL. > More examples of usages are showed below: > > %let x1 = 12.3; > %let x2 = 23; > %let x3 = 45.3; > > %picture(&x1 &x2 &x3, fmt= Output three values: xx.x xx, and xx.x) > == > Output three values: 12.3 23, and 45.3 > > %picture(&x1 &x2 &x3, fmt= Output estimated value and CI: xx.x > [xx,xx.x] ) == > Output estimated value and CI: 12.3 [23,45.3] > > The output formats for the macro are various and unlimited. > > Either data step or pure macro code can be used for the > implementation. > > I am not against using REGEX (regular expression functions) to > parsing the &fmt if there is no other better solution with basic macro > string functions. > > > LZ


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