Hi Experts,
Hope to seek if my understanding is correct that there is a limitation on the symput function when storing numeric values coming from a txt/csv file. Please see the code below and the outcomes.
options symbolgen mlogic mprint;
data hash;
infile "z:\desktop\hash.txt";
input hash :best32.;
format hash best32.;
run;
data _null_;
set hash;
call symput('hash',hash);
run;
%put &hash;
Case 1:
Value on hash.txt 1234567890.9
Macro variable hash: 1234567890.9
Case 2:
Value on hash.txt 1234567890.91
Macro variable hash: 1234567890.9
Case 3:
Value on hash.txt 1234567890.98
Macro variable hash: 1234567891
Am I correct that when it comes to case 3 that even I have read the file with best32. on the dataset it will store 1234567890.98 but when I use symput it would still get rounded on the macro variable. For SAS 9.1.3 it seems that it is defaulted to 12. if I do not specify an informat.
Regards,
Milton
Hi,
This phenomenon has nothing to do with "call symput", or should I say it is not specific to "call symput", rather, it happens during automatic numeric-character conversion, such as concatenation functions among others. SAS will then use BEST12 to do the conversion, and it is one digit shy in your case (the decimal point takes one), that is why the first one has no change, the second one rounded down and the third one rounded up.
To avoid this from happening, you need to tell SAS which format to use, and by doing so, you need to convert numeric to character proactively.
data _null_;
set hash;
call symput('hash',put(hash,best13.));
run;
You may still have the doubt that you have already give them the format best32., well, yes, but that is only for how they are displayed, not for how they are converted, the bottom line is that regardless the format, the numbers stored in SAS stay the same.
HTH,
Haikuo
Hi,
This phenomenon has nothing to do with "call symput", or should I say it is not specific to "call symput", rather, it happens during automatic numeric-character conversion, such as concatenation functions among others. SAS will then use BEST12 to do the conversion, and it is one digit shy in your case (the decimal point takes one), that is why the first one has no change, the second one rounded down and the third one rounded up.
To avoid this from happening, you need to tell SAS which format to use, and by doing so, you need to convert numeric to character proactively.
data _null_;
set hash;
call symput('hash',put(hash,best13.));
run;
You may still have the doubt that you have already give them the format best32., well, yes, but that is only for how they are displayed, not for how they are converted, the bottom line is that regardless the format, the numbers stored in SAS stay the same.
HTH,
Haikuo
Thanks for the explanation Haikuo!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.