Ahhh, yes, thanks Howard, I did forget to
state that it the stored digits can be used directly.
Yes indeed the basenum = &total;
gets replaced with the digits as they
are stored in the macro variable, so
as long as the digits were stored in
the format you want, the syntax is just
as if you hardcoded a literal. e.g.
basenum = &total;
turns into
basenum = 102105478;
if those were the characters stored.
Yeah, the INPUT() will also work if you
wanted to alter the format of the stored
characters.
Thanks for catching the straightforward omission.
Mark
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
Howard Schreier <hs AT dc-sug DOT org>
Sent: Thursday, September 14, 2006 9:13 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: Macro variable value rounded when assigned
On Thu, 14 Sep 2006 08:43:57 -0700, Terjeson, Mark
Yes, a good suggestion, because remember that macro variables are
character variables. And when re-using it later in a numeric context,
basenum = input("&total",9.);
I have to disagree with Mark here.
If &TOTAL is initialized in the manner of the original poster's SQL
code, the right hand side of the assignment statement
basenum = &total;
is not a character value. It's numeric. Using the INPUT function can
cause problems if there are more than 9 characters in the string or if
there are leading spaces in the macro variable.
Of course there are other situations where a special informat (eg, DATE
or
HEX) is required instead of the 9. Then Mark's construct is the way to
go.
put() -- convert numeric to character
input() -- convert character to numeric
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investment Group
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
toby dunn
Sent: Thursday, September 14, 2006 8:33 AM
Subject: Re: Macro variable value rounded when assigned
Auto ,
Explicitly put the value into a macro var instead of letting SAS do the
implicit conversion.
proc sql noprint ;
select Put( sum(Amount) , 10. -L ) Into :total
from mydata;
Quit ;
Toby Dunn
When everything is coming at you all at once, your in the wrong lane.
A truly happy person is someone who can smile and enjoy the scenery on
a detour.
Subject: Macro variable value rounded when assigned
Date: Thu, 14 Sep 2006 08:20:34 -0700
I'm creating a macro variable that has the total for a given variable
/column using proc sql . . .
proc sql noprint; select sum(Amount) into :total from mydata;
. . . the value is 102105478, after assigning it to a variable such
as . . .
base = &total ;
.. . . the value is 102110000, which is a rounded value (not what I
want).
I do use the total macro value in other calculations and they are
correct.
I've tried several different formats, but no luck.
Can someone explain this.
Thanks