- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.