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 (October 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 18 Oct 1999 20:43:37 -0500
Reply-To:   RSD <Rob@ROHRBOUGH-SYSTEMS.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   RSD <Rob@ROHRBOUGH-SYSTEMS.COM>
Subject:   Re: How do I format a macro variable
Comments:   To: lcdelac@pacbell.net
In-Reply-To:   <380B8084.3167@pacbell.net>
Content-Type:   text/plain; charset="iso-8859-1"

Drove me to testing. Two approaches here, easiest to leave the commas out - then no quoting function is necessary:

171 %let pdplst = GCR CGR CSC ; 172 %let seglst = G ; 173 %macro test(junk); 174 %local i; 175 %let i=1; 176 %do %while (%scan(&junk, &i) ^=); 177 %global new&i; 178 %let new&i = %sysfunc(putc(%scan(&junk, &i), $char5.)); 179 %let i=%eval(&i+1); 180 %end; 181 %mend test; 182 %test(&pdplst); 183 * process results...; 184 %put &new1 &new2 &new3; GCR CGR CSC 185 %test(&seglst); 186 * process results...; 187 %put &new1; G

I do recall one of the other respondents advising you use a quote function (rather than %str which forgives a number of similar sins) to take care of the overabundance of parameters:

137 %let pdplst = GCR, CGR, CSC ; 138 %let seglst = G ; 139 %macro test(junk); 140 %local i; 141 %let i=1; 142 %do %while (%scan(&junk, &i) ^=); 143 %global new&i; 144 %let new&i = %sysfunc(putc(%scan(&junk, &i), $char5.)); 145 %let i=%eval(&i+1); 146 %end; 147 %mend test; 148 %test(%quote(&pdplst)); 149 * process results...; 150 %put &new1 &new2 &new3; GCR CGR CSC 151 %test(&seglst); 152 * process results...; 153 %put &new1; G

You will need to substitute your table lookup format for $char5., however, either approach should get what you want...

Rob

> -----Original Message----- > From: leonora dela cruz [mailto:lcdelac@pacbell.net] > Sent: Monday, October 18, 1999 3:18 PM > To: RSD > Subject: Re: How do I format a macro variable > > > ,RSD wrote: > > > > Leonora, > > > > It would help if I had included an increment for i (also untested): > > > > ... > > %let i=1; > > %do %while (%scan(&junk, &i) ^=); > > %let new&i = %sysfunc(putn(%scan(&junk, &i),lookup.)); > > %let i=%eval(&i + 1); > > %end;= > > ... > > > > HTH a little more, > > > > Rob > > > > > -----Original Message----- > > > From: leonora dela cruz [mailto:lcdelac@pacbell.net] > > > Sent: Monday, October 18, 1999 7:15 AM > > > To: RSD > > > Subject: Re: How do I format a macro variable > > > > > > > > > RSD wrote: > > > > > > > > Not sure what your macro variables are - &pdplst? &GCR? > > > &CGR?... If you > > > > are calling %sysfunc with a first parameter of &pdplst, it will > > > fail because > > > > &pdplst will resolve to "GCR, CGR, CSC " - each term > between the commas > > > > appearing to the put function as a positional parameter. > > > > > > > > It appears that you will have to assign each of your initials > > > to a separate > > > > macro variable along the way - perhaps by parsing with > > > something like the > > > > scan function as follows (untested): > > > > > > > > %let pdplst = GCR, CGR, CSC ; > > > > %let seglst = G ; > > > > %macro test(junk); > > > > %local i; > > > > %let i=1; > > > > %do %while (%scan(&junk, &i) ^=); > > > > %let new&i = %sysfunc(putn(%scan(&junk, &i),lookup.)); > > > > %end; > > > > %mend test; > > > > %test(%str(&pdplst)); > > > > * process results...; > > > > %test(&seglst); > > > > * process results...; > > > > > > > > This assumes you have defined lookup. as your table lookup > > > format. You need > > > > to pass the value of &pdplst in a %str or similar macro > function so that > > > > %test recognizes all of its contents as the first and only > > > parameter. You > > > > need also to process the results of each call between calls > > > before the next > > > > call overwrites your newly-created macro variables &new1, > &new2, etc. > > > > > > > > HTH, > > > > > > > > Rob > > > > > > > > > -----Original Message----- > > > > > From: leonora dela cruz [mailto:lcdelac@PACBELL.NET] > > > > > Sent: Saturday, October 16, 1999 7:21 PM > > > > > Subject: Re: How do I format a macro variable > > > > > > > > > > > > > > > Hi SAS-lers, > > > > > > > > > > I used the macro below to format a number of macro variables. > > > > > Examples of macro variables are ; > > > > > > > > > > pdplst = GCR, CGR, CSC ; > > > > > seglst = G ; > > > > > > > > > > I used two formats that convert the values > > > > > > > > > > i.e. GCR to Great Central Region > > > > > CGR to Central Great Region etc. > > > > > > > > > > i.e. G to Good Results > > > > > > > > > > The formatted value for G resolves correctly to > > > > > Good Results but the first one has an error: > > > > > The error is more positional parameters found than defined. > > > > > > > > > > What is it that I am missing here? > > > > > > > > > > I would appreciate a reply or opinion on this. > > > > > > > > > > Thanks. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -------------------------------------------------------------------- > > > > > Lund, Pete wrote: > > > > > > > > > > > > Wendy- > > > > > > You can use the %SYSFUNC function to format a macro > > > variable value. > > > > > > For example: > > > > > > > > > > > > %macro test; > > > > > > %do i = 1 %to 10; > > > > > > %let newi = %sysfunc(putn(&i,z2.)); /* put the macro > > > variable &I in > > > > > > z2. Format */ > > > > > > %put &i &newi; > > > > > > %end; > > > > > > %mend; > > > > > > %test > > > > > > > > > > > > produces > > > > > > > > > > > > 1 01 > > > > > > 2 02 > > > > > > 3 03 > > > > > > 4 04 > > > > > > 5 05 > > > > > > 6 06 > > > > > > 7 07 > > > > > > 8 08 > > > > > > 9 09 > > > > > > 10 10 > > > > > > > > > > > > Hope this helps- > > > > > > Pete Lund > > > > > > WA State Caseload Forecast Council > > > > > > (360) 902-0086 > > > > > > peter.lund@cfc.wa.gov > > > > > > > > > > > > -----Original Message----- > > > > > > From: Wendy Watson > > > [mailto:wendy.watson@COVANCE.COM] > > > > > > Sent: Tuesday, July 14, 1998 9:31 AM > > > > > > To: SAS-L@UGA.CC.UGA.EDU > > > > > > Subject: How do I format a macro variable > > > > > > > > > > > > Hello everyone. > > > > > > > > > > > > Can someone tell me a good way to format a macro > > > > > > variable? > > > > > > > > > > > > For example : > > > > > > > > > > > > I have a macro variable called counter. > > > counter = 1, 2, > > > > > > 3 - 10. > > > > > > > > > > > > How do I get counter to = 01, 02, 03 - 10 > > > (so that > > > > > > counter has a > > > > > > format of z2.) ? > > > > > > > > > > > > Thanks for your help. > > > > > > > > > > > > > > > ----------------------------------------------------- > > > > > > Confidentiality Notice: This e-mail transmission > > > > > > may contain confidential or legally privileged > > > > > > information that is intended only for > the individual > > > > > > or entity named in the e-mail address. If > > > you are not > > > > > > the intended recipient, you are hereby > notified that > > > > > > any disclosure, copying, distribution, > or reliance > > > > > > upon the contents of this e-mail is > > > strictly prohibited. > > > > > > > > > > > > If you have received this e-mail > > > transmission in error, > > > > > > please reply to the sender, so that Covance > > > can arrange > > > > > > for proper delivery, and then please delete > > > the message > > > > > > from your inbox. Thank you. > > > > > > > > Hi Rob, > > > > > > I did try your code. It's looping. > > > > > > I used the exact codes you have given. > > > > > > By the way, thanks for the help. > > > > > Hi Rob, > > Sorry, but it didn't work with the same message generated when I > tried it using the original code. >


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