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

Hi,

How can i convert my 16-18 digit long number to simple string  just like it happens with TO_CHAR in sql.

 

I am using below to convert number to character:, the purpose to use $20. is to make sure  if my digits are  more than 16 digits still it get converted to String-. Basically I am trying to use SAS version of TO_CHAR in SQL. STRIP is used to remove trailing and leading spaces which might get added to the chr_var as a result of PUT function

data new;
no_var = 12345678910111214;
chr_var = strip(put(no_var, $20.));
run;

 

Issue is it runs fine in the seclusion but when added to the actual script it gives below error.

 

ERROR: Character format $ in PUT function requires a character argument.

 

Appreciate the help.

RDS

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Editors note:  Thanks for the correct response here, @novinosrin .  I am also pasting the important reminder from   @FreelanceReinh  below  due to the size of the numeric value that is to be printed.

 

chr_var = strip(put(no_var, 20.));

Regardless of the conversion details you should be aware of the limitations of how SAS stores numeric values: See Maximum Integer Size and try no_var = 12345678910111213 or no_var = 123456789101112147 to see what can happen to the least significant digit(s). Unless your "16-18 digit long" numbers meet certain numeric conditions, you would need to resort to the BIGINT data type, which is available in the DS2 language and in FedSQL, but not in the DATA step, or better store them in character variables in the first place.

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Editors note:  Thanks for the correct response here, @novinosrin .  I am also pasting the important reminder from   @FreelanceReinh  below  due to the size of the numeric value that is to be printed.

 

chr_var = strip(put(no_var, 20.));

Regardless of the conversion details you should be aware of the limitations of how SAS stores numeric values: See Maximum Integer Size and try no_var = 12345678910111213 or no_var = 123456789101112147 to see what can happen to the least significant digit(s). Unless your "16-18 digit long" numbers meet certain numeric conditions, you would need to resort to the BIGINT data type, which is available in the DS2 language and in FedSQL, but not in the DATA step, or better store them in character variables in the first place.

 

FreelanceReinh
Jade | Level 19

Hi @RDS2020,

 

Regardless of the conversion details you should be aware of the limitations of how SAS stores numeric values: See Maximum Integer Size and try no_var = 12345678910111213 or no_var = 123456789101112147 to see what can happen to the least significant digit(s). Unless your "16-18 digit long" numbers meet certain numeric conditions, you would need to resort to the BIGINT data type, which is available in the DS2 language and in FedSQL, but not in the DATA step, or better store them in character variables in the first place.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 13290 views
  • 1 like
  • 3 in conversation