column value from column name

Get column value from column name

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.

VValue function

The VValue returns the formatted value associated with the variable you specify.

data new;
set one;
vvalue=vvalue(val);
a1=val;
run;
Get column value from column name

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.

column value from column name

VValuex Function

VVALUEX evaluates the argument to determine the variable name and then returns the value that is associated with that variable name.

VVALUEX returns a character string containing the current value of the argument you specify. The value is formatted using the format currently associated with the argument.

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;
column value from column name

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro

Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.