Sometimes we need to use the attributes like the column value from the column name or the format of a variable within a data set.
Normally, this can be achieved with a simple CONTENTS procedure, but SAS functions make programming more efficient.
Some of the functions are the variable information functions. These functions allow the programmer to use the information about the variable within the data step without having to hard code the information or writing a secondary step to fetch data from PROC CONTENTS.
The Vvalue and Vvaluex functions can be used to return the format and/or value of a variable or a string within the data step.
The VValue returns the formatted value associated with the variable you specify.
data new; set one; vvalue=vvalue(val); a1=val; run;
VVALUE and an assignment statement return the current value of the variable you specify. However, With VVALUE, the value is formatted using the current format associated with the variable. With an assignment statement, however, the value returned is unformatted.
VVALUEX evaluates the argument to determine the variable name and then returns the value that is associated with that variable name.
Get column value from the column name.
The VValuex function can get the column value from the column name. Consider the below example where we want to get the value of the respective column specified in the Marks Column for each row.
data have; input (Marks Marks1 Marks2 Marks3) (:$8.); cards; Marks2 1 2 3 Marks1 4 5 6 Marks1 7 8 9 Marks3 10 11 12 ; run; data want; set have; value=vvaluex(marks); run;