BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
milts
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

2 REPLIES 2
Haikuo
Onyx | Level 15

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

milts
Pyrite | Level 9

Thanks for the explanation Haikuo!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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