I don't understand why the generated macro variable is not printed with decimal values, but only the integer part:
data test;
x=16017854.36;
run;
proc sql noprint;
select x into:x from test;
quit;
%put x=&x.;
proc sql noprint;
select x format=12.2 into :x from test;
quit;
%put &=x;
proc sql noprint;
select x format=12.2 into :x from test;
quit;
%put &=x;
In SAS SQL when no format is specified for a variable length the format defaults to best8.
This was causing anything beyond 8 characters to be truncated. Therefore the proper approach is to use format as rightly suggested by @PaigeMiller.
Something to always keep in mind: the SAS macro language is text. So any "number" requires you to take control to create the needed text representation of the numeric value, i.e. a format most of the time.
Also use of values with decimal portions are likely to require the macro function %SYSEVALF to actually use the decimal portion. Consider this brief example of attempting to add 10 to a decimal valued macro variable:
%let value= 123.45; %let newvalue_1 = %eval(&value. + 10); %let newvalue_2 = %sysevalf(&value. + 10); %put newvalue_1 is: &newvalue_1. and newvalue_2 is: &newvalue_2.;
Note that without %eval or %sysevalf you would get text of "123.45 + 10", not the arithmetic value.
The log:
1 %let value= 123.45; 2 3 %let newvalue_1 = %eval(&value. + 10); ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 123.45 + 10 4 %let newvalue_2 = %sysevalf(&value. + 10); 5 6 %put newvalue_1 is: &newvalue_1. and newvalue_2 is: &newvalue_2.; newvalue_1 is: and newvalue_2 is: 133.45
You might ask why did I use %eval. That is what SAS will by default call internally if you attempt a number of uses.
You may also find this of use:
%macro dummy(value); %if &value. > 1000 %then %put value is greater than 1000; %else %put value is not greater than 1000; %mend; %dummy(123); %dummy(123.45);
With result
40 %dummy(123); value is not greater than 1000 41 %dummy(123.45); value is greater than 1000
and wonder why that second result?
Consider:
42 %dummy(abc); value is greater than 1000
Remember my comment about macros and text? When using a value that represents an integer with the comparison you get SAS %eval result because it works as SAS is attempting to help you. But when the value is not an integer the comparison is CHARACTER based. Since the second character 2 is "greater than" 0 then the comparison stops and is "greater than" using character rules. And the same with abc. "a" is greater than "1".
This is the sort of thing that happens to generate unexpected results in the macro language when you test code and it "works" then use with other ranges of values such as testing with integers and then actual values are decimal.
Alternatively, you can use CALL SYMPUTX in data step, which passes your decimals and long numeric values (up to 17 I believe) into macro variable without truncation.
data test;
x=16017854.36;
call symputx('x', x);
run;
%put &=x;
log:
X=16017854.36
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.