Hello
I saw in internet an example when using format statement to increase the length of the macro variable.
In this example we increase the length from 14 to 16.
My question is why should we increase the length?
Can anyone show an example when the length of 16 help us?
(I ask what is the beneficial of doing that?)
data one;
x=98765432123456;
run;
proc sql noprint;
select x format=16. into :mac_var
from one;
quit;
%put &mac_var;
Edit by KB: fixed typo in the subject line
If someone wants the leading blanks, this is the way to get them. If you slightly change your code:
data one;
x=98765432123456;
run;
proc sql noprint;
select x format=16. into :mac_var
from one;
quit;
%put "&mac_var";
you can see in the log that the blanks are actually there:
36 %put "&mac_var"; " 98765432123456"
The biggest importance is this: if you do not use a format in the SQL, SAS defaults to 8. (!), causing the number to be stored in the macro variable with the best8. format, which then converts it to 9.877E13, completely losing most of the precision in the process. Using a wide enough format (16. accommodates the maximally possible precision for SAS numbers) prevents that. If you have no clue about the possible ranges, I'd even use best32. to have space for all digits in the mantissa, exponent and eventual sign.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.