BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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

 

1 REPLY 1
Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1849 views
  • 3 likes
  • 2 in conversation