0

I have the following statement within my SAS code taken from another person and I cannot figure out what it does. It is inside the DATA step when apparently creating a new variable named variable_X:

variable_X = input(put(variable, variable_X.), best32.);

Can somebody explain me the logic behind this combination of input and put please?

doremi
  • 141
  • 3
  • 15

1 Answers1

0

In SAS a format is used to convert values to text and an informat is used to convert text to values.

The code you showed is using the format VARIABLE_X. to convert the values of numeric variable named VARIABLE into text that the normal 32. informat can read. (There is no BEST informat, it is just an alias for the normal w.d numeric informat. Other aliases are F, D, and E.)

Sounds like they are trying to transform the numbers into different numbers using a format and the put() function. But they want to generate a number instead of a character string so they convert the string back into a number using the input() function.

Tom
  • 47,574
  • 2
  • 16
  • 29
  • And would it work if VARIABLE is not numeric, but character variable? And do you know where could I find this `VARIABLE_X.` format, how was it defined? – doremi Mar 23 '20 at 13:33
  • If VARIABLE is character then you would need a character format instead, say $VARIABLE_X. Also if VARIABLE is character you can simplify by using an user defined informat instead. Then you just need the INPUT() function. You can see the format definition using PROC FORMAT with the FMTLIB. Use the SELECT statement if you just want to see one format from the catalog. Check the setting of the FMTSEARCH option to see which format catalog(s) to search. – Tom Mar 23 '20 at 13:35