- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi experts
I'd like to convert a normal text to ascii code, for example: in my dataset I have the letter "t" and the value that i want is 116 and so on with the other letters or numbers.
do you know a way to do it? the final result that I want is a file in that format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The easiest way is to display the values in HEX instead of decimal.
data have;
input string $20.;
cards;
The rain in Spain
falls mainly on
the plain.
;
data want;
set have;
codes = put(string,$hex40.);
run;
Results
Obs string codes 1 The rain in Spain 546865207261696E20696E20537061696E202020 2 falls mainly on 66616C6C73206D61696E6C79206F6E2020202020 3 the plain. 74686520706C61696E2E20202020202020202020
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The rank function returns the ascii code for a character.
data _null_;
file print;
ascii_code=rank('t');
put ascii_code;
run;
the final result that I want is a file in that format.
Like a text file with all the characters replaced with their respective ASCII code? And I guess that all ASCII codes would need to take-up 3 positions so you know where they start and end.
Why ASCII codes which is very unusual and not HEX values?
....and just thinking: May-be tell us what the purpose for such conversion is. There might be other ways for achieving the same goal.