BookmarkSubscribeRSS Feed
0 Likes

Can we get easy to remember/use functions that go between text and numeric?  For example, just something like

 

variable = as_numeric(variable) /* From character to numeric */

-or-

variable = as_character(variable) /* From numeric to character */

 

would be a big improvement over trying to remember if I need to use put or input (can never keep them straight) and trying to remember the format requirements that go along with it - do I need $ or . and do I need some sort of length with that?  

6 Comments
RW9
Diamond | Level 26
Diamond | Level 26

The question you need to ask is, should I, rather than remember two simple things, expect everyone else to change their known language functions?  The answer is no.  It is very simple:

Char to number = input

Num to char = put

 

What, other than breaking backwards compatibility, and removing what knowledge people have on the language now, would changing the names add?  

Kurt_Bremser
Super User

input() andf put() are simple enough, and having the power of determining the format makes them extremely versatile tools. Tools that I had no problem with from week one of my SAS training.

mark4
Obsidian | Level 7

I'm not suggesting they remove the previous options, just add this as different option.  Input for char -> num and put for the opposite seems so arbitrary, and I can never remember arbitrary things.  (The only way I keep left/right straight is by the callus on my writing hand.)  Every time I want to use it, I have to look-up which I need to use or guess & try the other if it doesn't work.

Kurt_Bremser
Super User

You can easliy roll your own with a macro:

%macro to_num(variable);
input(&variable,best.)
%mend;

%macro to_char(variable);
put(&variable,best.)
%mend;

From then on, use %to_num() and %to_char()

mark4
Obsidian | Level 7

Great, thanks.  And is that available in all use cases - like data steps, sql, etc?  

Kurt_Bremser
Super User

Put the maco definitions in your autoexec, or use the autocall facility.