SAS: PUT VS. INPUT
- 1 minOverview
When it comes to converting data type or variable type in SAS, it is always challenging to figure out when to use PUT
and when to use INPUT
.
The PUT
function can be applied to a character or numeric input, but the output of the Put function is always character.
The INPUT
function can only be applied to a character target, but the output can be character or numeric.
“In the old, old days” data sources and destinations were usually text.
INPUT
statements, andINFORMAT
s, convert external “text files” into either SAS® character or numeric variables in a SAS data set– converting from “text only” to two types of variables
PUT
statements, andFORMAT
s, are used to convert SAS character and numeric variables “into character” – two types into one.
Illustration
A. PUT()
converts character variable to another character variable.
B. PUT()
converts numeric variable to a character variable with numeric value.
C. PUT()
converts character variable with a user defined format to another character variable.
D. INPUT()
converts character variable with numeric value and informat to a numeric variable.
E. INPUT()
converts character variable with numeric value and informat to a character variable.
F. INPUT()
converts character variable with numeric value and informat to a numeric variable.
Reference
- An Animated Guide: Using the Put and INput functions
- Converting variable types—use PUT() or INPUT()?