DATA Step, Macro, Functions and more

Symput limitation

Accepted Solution Solved
Reply
Super Contributor
Posts: 321
Accepted Solution

Symput limitation

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


Accepted Solutions
Solution
‎06-14-2013 11:41 PM
Respected Advisor
Posts: 3,124

Re: Symput limitation

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

View solution in original post


All Replies
Solution
‎06-14-2013 11:41 PM
Respected Advisor
Posts: 3,124

Re: Symput limitation

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

Super Contributor
Posts: 321

Re: Symput limitation

Thanks for the explanation Haikuo!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 831 views
  • 0 likes
  • 2 in conversation